forked from nayuki/Project-Euler-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp029.java
More file actions
34 lines (27 loc) · 839 Bytes
/
p029.java
File metadata and controls
34 lines (27 loc) · 839 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
/*
* Solution to Project Euler problem 29
* Copyright (c) Project Nayuki. All rights reserved.
*
* https://www.nayuki.io/page/project-euler-solutions
* https://github.com/nayuki/Project-Euler-solutions
*/
import java.math.BigInteger;
import java.util.HashSet;
import java.util.Set;
public final class p029 implements EulerSolution {
public static void main(String[] args) {
System.out.println(new p029().run());
}
/*
* We generate all the possible powers in the given range, put each value
* into a set, and let the set count the number of unique values present.
*/
public String run() {
Set<BigInteger> generated = new HashSet<>();
for (int a = 2; a <= 100; a++) {
for (int b = 2; b <= 100; b++)
generated.add(BigInteger.valueOf(a).pow(b));
}
return Integer.toString(generated.size());
}
}