啊哈挑战48:守形数

       题目链接:http://tz.ahalei.com/problems/view/48

       思路:我的方法是暴力穷举(也就是没有方法,虽然通过简单的推理可以知道个位数只能是0,1,5,6,但没有大用处)。但这题要注意,穷举的i最大达到1e8,平方i*i达到1e16,超过了32位整型的表达范围,故需要用64位整型或double。

#include 
#include 
#include 
using namespace std;

clock_t start__;
#define tic start__=clock()
#define toc cout<<(clock()-start__)*1000/CLOCKS_PER_SEC<<"ms\n"

int fun(int k)
{// k是当前要统计的位数范围
	unsigned __int64 i;
	int sum=0, l, r;
	for(l=i=1;i



       网站的答案15是错误的!我用Mathematica软件验算过上述17个数,都是准确无误的。另一方面,无符号64位整型的计算范围达到18e18,完全超过题目计算最大中间值1e16,所以C++跑出的答案肯定也是精确的。

你可能感兴趣的:(C/C++)