我需要蛮力一年的锻炼。编译器不断抛出这个错误:
bruteforceJS12.cpp:8:28:警告:整数常量对于它的类型来说太大了[默认启用]
我的代码是:
#include <iostream>
using namespace std;
int main(){
unsigned long long year(0);
unsigned long long result(318338237039211050000);
unsigned long long pass(1337);
while (pass != result)
{
for (unsigned long long i = 1; i<= year; i++)
{
pass += year * i * year;
}
cout << "pass not cracked with year = " << year << endl;
++year;
}
cout << "pass cracked with year = " << year << endl;
}
请注意,我已经尝试过unsigned long long result(318338237039211050000ULL);
我正在使用 gcc 版本 4.8.1
编辑:
这是使用 InfInt 库http://code.google.com/p/infint/的更正版本
#include <iostream>
#include "InfInt.h"
using namespace std;
int main(){
InfInt year = "113";
InfInt result = "318338237039211050000";
InfInt pass= "1337";
while (pass != result)
{
for (InfInt i = 1; i<= year; i++)
{
pass += year * i * year;
}
cout << "year = " << year << " pass = " << pass << endl;
++year;
}
cout << "pass cracked with year = " << year << endl;
}