Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // finding sum of all primes under 2 million
- public class lll {
- public static void main(String[] args)
- {
- int a = 2 ;
- int b = 0 ;
- int c = 0 ;
- while (a<2000000)
- {
- int i = 1;
- for (i = 1; i*i<=a; i++)
- {
- if (a%i == 0)
- //if factor is found of number a b goes up 1
- {b ++ ;
- }
- }
- // all primes have only one factor <= sqrt (1)
- if (b==1)
- // if b =1 , a is prime so c+=a
- {c += a ;
- }
- //reset b and add one to a to move on
- b = 0 ;
- a++ ;
- // for error checking see description
- System.out.println(c);
- }
- System.out.println(c);
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement