我需要對一年的練習進行暴力破解。編譯器不斷拋出此錯誤:C++:整數常量對於其類型來說太大
bruteforceJS12.cpp:8:28: warning: integer constant is too large for its type [enabled by default]
我的代碼是:
#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庫012的更正版本
#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;
}
您應該使用ASCII表示法。 –
使用'unsigned long long result = 318338237039211050000ULL;'失敗嗎?它可能只是它不喜歡這種初始化方法? –
@ScottMermelstein:文字後綴不適用於* that *目的。如果存在這樣的類型,則整型文字已具有可表示它的類型。 –