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?
这种数字满足下面条件:
对于数位为x的数S=k^x 有 10^(x-1)<=k^x<=10^x-1
#include "stdafx.h" #include <iostream> using namespace std; int main() { int count = 0; for (int i = 1; i < 100; i++) { double n = pow(10, 1.0 - 1.0 / i); int tmp = int(n); if (n - tmp>0.0) tmp++; if (tmp > 9) break; count += 9 - tmp + 1; //cout << n << " " << tmp << endl; } cout << count << endl; system("pause"); return 0; }