-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoLacPrimeSum.java
More file actions
47 lines (29 loc) · 939 Bytes
/
Copy pathTwoLacPrimeSum.java
File metadata and controls
47 lines (29 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
This program is just display the Sum of 2 lac's Prime number
*/
class TwoLacPrimeSum
{
public static boolean checkPrime ( final long number ) {
final double limit = Math.floor ( Math.sqrt ( number ) );
for( long i = 2; i <= limit ; i++ ){
if( number % i == 0 ) return false;
}
return true;
}
public static void main( String [] args ) {
long loop = 2;
long counter = 0;
long sum = 0;
final long limit = 200000;
while ( true ) {
if ( Prime.checkPrime( loop ) ) {
counter = counter + 1;
sum = sum + loop;
// System.out.println(i + " " + sum);
}
else if ( counter == limit ) break;
++ loop;
}
System.out.println( " \n Sum of 2 lac's Prime number = " + sum );
}
}