【发布时间】:2011-07-20 10:55:43
【问题描述】:
unsigned long long terms;
unsigned long long test;
unsigned long long digit = 1;
unsigned long long max = 0;
//cout<<sizeof(long)<<" "<<sizeof(int)<<endl;
//cout<<digit<<endl;
for(;digit<1000000;++digit)
{
terms = 1;
test = digit;
while(test>1)
{
if(0==(test%2))
{
test /=2;
}else{
test = test *3 +1;
}
terms ++;
}
if(terms>max)
max = terms;
}
//terms = get_chain_length();
/*if(terms>max)
max = terms;*/
//cout<<sizeof(long long)<<endl;
cout<<max<<endl;
超出 INT_MAX,我该如何纠正?我尝试以递归方式使用 Hash_map,但堆栈了。
【问题讨论】:
-
虽然这个问题是众所周知的,但对于每个在 Project Euler 上浪费时间的人来说,这似乎是一个剧透解决方案!
标签: c++