fixed bug when n=5000

This commit is contained in:
Krishna Vedala 2020-03-29 23:20:41 -04:00
parent feaf57d4a3
commit ad84e9b08d
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7

View File

@ -25,7 +25,7 @@ int main(int argc, char* argv[])
* if i^th cell is '1', then 'i' is composite
* if i^th cell is '0', then 'i' is prime
*/
for (long i = 2; i < sqrtl(n)+1; i++)
for (long i = 2; i < sqrtl(n); i++)
{
/* if i^th element is prime, mark all its multiples
as composites */
@ -35,11 +35,11 @@ int main(int argc, char* argv[])
{
sieve[j] = 1;
}
// sum += i;
sum += i;
}
}
for (long i = 2; i < n; i++)
for (long i = sqrtl(n)+1; i < n; i++)
if (!sieve[i])
sum += i;