Skip to content

Instantly share code, notes, and snippets.

@rohitvvv
Created February 14, 2017 15:47
Show Gist options
  • Save rohitvvv/b0dbb512ee73b72cc1592107c221e841 to your computer and use it in GitHub Desktop.
Save rohitvvv/b0dbb512ee73b72cc1592107c221e841 to your computer and use it in GitHub Desktop.
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);
}
}
@anvaypatil
Copy link

Citing to this Line-16, i=i+2 will make the loop twice faster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment