lordmat

Problem 10

Jun 15th, 2011
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. /**
  2.  *
  3.  * @author Mat
  4.  */
  5. package problem.pkg10;
  6.  
  7. import java.math.BigInteger;
  8.  
  9. public class Problem10 {
  10.  
  11.     public static void main(String[] args) {
  12.         BigInteger total = new BigInteger("2");
  13.         final int TWO_MILLION = 2000000;        
  14.        
  15.         for(BigInteger i = new BigInteger("3");
  16.                 i.compareTo(BigInteger.valueOf(TWO_MILLION)) < 0;
  17.                 i = i.add(BigInteger.valueOf(2))){
  18.            
  19.             //Testing if prime if so add it to total
  20.             if(i.isProbablePrime(10)){
  21.                 total = total.add(i);                
  22.             }
  23.        }      
  24.         System.out.println("The total is: " + total.toString());
  25.     }
  26. }
  27. /* Output
  28.  * The total is: 142913828922
  29. */
Advertisement
Add Comment
Please, Sign In to add comment