Problem 63 Powerful digit counts


Powerful digit counts

Problem 63

The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is a ninth power.

How many n-digit positive integers exist which are also an nth power?



注意不要理解错题意了,题目是问像16807,134217728之类的数字有多少个。


直接暴力就可以了啊

import java.math.BigInteger;

public class Main {
	static int maxn = 1000;

	public static void main(String[] args) {
		int ans = 0;
		for (int j = 1; j < maxn; j++) {
			for (BigInteger i = BigInteger.ONE;; i = i.add(BigInteger.ONE)) {
				int len = i.pow(j).toString().length();
				if (len > j)
					break;
				else if (len == j)
					ans++;
			}
		}
		System.out.println(ans);
	}

}


很久没在博客上写东西了 ==。

你可能感兴趣的:(ProjectEuler)