* disclaimer when I say: "I have confirmed that this is the correct result", please interpret this as I have checked my decision against the answer according to WolframAlpha, which I find to be fairly accurate.
* to find the sum of all primes less than or equal to 2,000,000 (two million)
*, my code will give the correct result when my range of tested values is approximately less than or equal to
I do not give the correct result as soon as the test input becomes more than approximately 1,300,000; my output will be disabled ...
test input: ---- 199.999 test output: --- 709 600 813 correct result: 1 709 600 813
test input: ---- 799.999 test output: --- 24,465,663,438 correct result: 24,465,663,438
test input: ---- 1,249,999 test output: --- 57 759 511 224 correct result: 57 759 511 224
test input: ---- 1,499,999 test output: --- 82 075 943 263 correct result: 82 074 443 256
test input: ---- 1 999 999 test output: --- --- --- --- --- --- --- --- --- --- --- --- - - --- --- --- --- - - the correct result: 142 913 828 925
test input: ---- 49,999,999 test output: --- 72 619 598 630 294 correct result: 72 619 548 630 277
* my code, what happens, why does it work for small resources? I even used long, not int ...
long n = 3;
long i = 2;
long prime = 0;
long sum = 0;
while (n <= 1999999) {
while (i <= Math.sqrt(n)) {
if (n % i != 0) {
i += 2;
} else {
i = 3;
n += 2;
}
}
prime = n;
sum = sum + prime;
i = 3;
n += 2;
}
System.out.println(sum+2);
help me please:)