首页 > 其他 > 详细

Project Euler:Problem 63 Powerful digit counts

时间:2015-07-14 17:57:04      阅读:225      评论:0      收藏:0      [点我收藏+]

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

原文:http://blog.csdn.net/youb11/article/details/46880651

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!