math - Project Euler #10 Java solution not working -
I am trying to find the sum of key numbers & lt; 2,000,000 This is my solution in Java but I can not find the correct answer.
Returns the 'amount': 1308111344, which is wrong.
Edit: Thanks for all help. Changed for a long time and & lt; & Lt; = And it is unable to work, but inefficient way to find the key numbers :)
/ * The sum of the prices of 10 2 + 3 + 5 + 7 = 17 20 Find out the amount of prime of all below million. * / Class assistant {goes public zero () {integer sum = 0; For (IntiI = 2; I <2000000; i ++) {If (ISPremium (I)) Yoga + i =; } System.out.println (sum); } Private boolean isPrime (int nr) {if (NR == 2) is true; And if (nr == 1) wrong return; If (nr% 2 == 0) return false; For (Int i = 3; I & lt; Mathematics. SCRT (NR); I + = 2) {If (NR% i == 0) returns false; } Back true; }} Class problem {public static zero main (string [] args) {helper p = new helper (); P.run (); }}
The result will be too large to fit in a round, so you Trying to use one or the other instead this case is quite long.
Comments
Post a Comment