码迷,mamicode.com
首页 > 其他好文 > 详细

Project Euler:Problem 63 Powerful digit counts

时间:2015-07-14 17:58:13      阅读:195      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!