forked from nayuki/Project-Euler-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp007.java
More file actions
31 lines (25 loc) · 714 Bytes
/
p007.java
File metadata and controls
31 lines (25 loc) · 714 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
/*
* Solution to Project Euler problem 7
* Copyright (c) Project Nayuki. All rights reserved.
*
* https://www.nayuki.io/page/project-euler-solutions
* https://github.com/nayuki/Project-Euler-solutions
*/
public final class p007 implements EulerSolution {
public static void main(String[] args) {
System.out.println(new p007().run());
}
/*
* Computers are fast, so we can implement this solution by testing each number
* individually for primeness, instead of using the more efficient sieve of Eratosthenes.
*/
public String run() {
for (int i = 2, count = 0; ; i++) {
if (Library.isPrime(i)) {
count++;
if (count == 10001)
return Integer.toString(i);
}
}
}
}