-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp063.java
More file actions
32 lines (25 loc) · 813 Bytes
/
p063.java
File metadata and controls
32 lines (25 loc) · 813 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
package level03;
import java.math.BigInteger;
import org.junit.Test;
import lib.EulerTest;
public class p063 extends EulerTest {
final int L = 9;
/**
* Find the number of n-digit positive integers that are nth powers, for any n.
* <p>
* If b≥10, then b^n will have at least n+1 digits, so only check base≤9. Increment n and stop
* once b^n has fewer than n digits, because if b≤9, then incrementing n will not cause b^n to
* grow by more than a single digit.
*/
@Test
public void test() {
for (int i : rangeC(1, L)) {
BigInteger base = big(i);
int len;
for (int n = 1; (len = (base.pow(n) + "").length()) >= n; n++)
if (len == n)
ans++;
}
check(49);
}
}