Created
February 14, 2017 15:47
-
-
Save rohitvvv/b0dbb512ee73b72cc1592107c221e841 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PrimeSum { | |
static boolean isPrime(Integer x){ | |
if(x==2) | |
return true; | |
if(x%2==0) | |
return false; | |
for(Integer j=2;j<=Math.sqrt(x);j++){ | |
if(x%j==0) | |
return false; | |
} | |
return true; | |
} | |
public static void main(String[] args) { | |
Long sum =(long) 0; | |
for(Integer i=2;i<1500000;i++){ | |
if(isPrime(i)) | |
sum+=i; | |
} | |
System.out.println(sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Citing to this Line-16, i=i+2 will make the loop twice faster