标签:c++ project euler
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;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
Project Euler:Problem 63 Powerful digit counts
标签:c++ project euler
原文地址:http://blog.csdn.net/youb11/article/details/46880651