-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProb10.java
60 lines (53 loc) · 1.24 KB
/
Prob10.java
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
48
49
50
51
52
53
54
55
56
57
58
59
60
package gevaexs.PE;
import java.math.BigInteger;
public class Prob10 {
public static void main(String[] args)
{
BigInteger sum = new BigInteger("0");
for(int i = 2; i < 257; i++)
{
if(isPrime(i)){
sum = sum.add(new BigInteger(i + ""));
System.out.println("i: " + i);
}
}
System.out.println( "sum: " + sum );
System.out.println("1" + isPrime(256));
}
public static boolean isPrime(int num)
{
for(int i = 2; i < num; i++)
{
if(num%i ==0)
return false;
}
return true;
}
}
//Answer: 142913828922
// 6min 12sec
/// WOW BEST ASNWER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// public static void main(String[] args) {
// int curPrime = 5;
// long summation = 5; //2 + 3
//
// while(curPrime < 2000000) {
// if(isPrime(curPrime)) {
// summation += curPrime;
// }
//
// curPrime += 2;
// }
//
// System.out.println(summation);
// }
//
// public static boolean isPrime(int val) {
// for(int x = 3; x <= (int)Math.sqrt(val); x += 2) {
// if(val % x == 0) {
// return false;
// }
// }
//
// return true;
// }