結果

問題 No.1312 Snake Eyes
ユーザー pes_magicpes_magic
提出日時 2020-12-20 19:21:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 992 bytes
コンパイル時間 955 ms
コンパイル使用メモリ 84,460 KB
実行使用メモリ 66,884 KB
最終ジャッジ日時 2023-08-20 11:28:09
合計ジャッジ時間 25,274 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 239 ms
66,628 KB
testcase_01 AC 242 ms
66,544 KB
testcase_02 AC 252 ms
66,572 KB
testcase_03 AC 241 ms
66,620 KB
testcase_04 AC 240 ms
66,668 KB
testcase_05 AC 241 ms
66,696 KB
testcase_06 AC 244 ms
66,852 KB
testcase_07 AC 240 ms
66,680 KB
testcase_08 AC 242 ms
66,608 KB
testcase_09 AC 237 ms
66,608 KB
testcase_10 AC 240 ms
66,680 KB
testcase_11 AC 241 ms
66,552 KB
testcase_12 AC 242 ms
66,612 KB
testcase_13 AC 240 ms
66,560 KB
testcase_14 AC 241 ms
66,560 KB
testcase_15 AC 240 ms
66,572 KB
testcase_16 AC 242 ms
66,552 KB
testcase_17 AC 239 ms
66,556 KB
testcase_18 AC 244 ms
66,612 KB
testcase_19 AC 242 ms
66,544 KB
testcase_20 AC 240 ms
66,624 KB
testcase_21 AC 238 ms
66,624 KB
testcase_22 AC 239 ms
66,620 KB
testcase_23 AC 239 ms
66,676 KB
testcase_24 AC 242 ms
66,744 KB
testcase_25 AC 242 ms
66,832 KB
testcase_26 AC 242 ms
66,544 KB
testcase_27 AC 241 ms
66,596 KB
testcase_28 AC 240 ms
66,544 KB
testcase_29 AC 240 ms
66,600 KB
testcase_30 AC 237 ms
66,612 KB
testcase_31 AC 241 ms
66,832 KB
testcase_32 AC 248 ms
66,556 KB
testcase_33 AC 240 ms
66,848 KB
testcase_34 AC 241 ms
66,596 KB
testcase_35 AC 241 ms
66,884 KB
testcase_36 AC 239 ms
66,556 KB
testcase_37 AC 238 ms
66,556 KB
testcase_38 AC 241 ms
66,588 KB
testcase_39 AC 239 ms
66,796 KB
testcase_40 AC 237 ms
66,680 KB
testcase_41 AC 239 ms
66,568 KB
testcase_42 AC 237 ms
66,716 KB
testcase_43 AC 240 ms
66,836 KB
testcase_44 AC 241 ms
66,596 KB
testcase_45 AC 240 ms
66,804 KB
testcase_46 AC 241 ms
66,600 KB
testcase_47 AC 241 ms
66,736 KB
testcase_48 AC 248 ms
66,744 KB
testcase_49 AC 252 ms
66,544 KB
testcase_50 AC 248 ms
66,592 KB
testcase_51 AC 244 ms
66,680 KB
testcase_52 AC 255 ms
66,560 KB
testcase_53 AC 248 ms
66,560 KB
testcase_54 AC 251 ms
66,556 KB
testcase_55 AC 244 ms
66,744 KB
testcase_56 AC 247 ms
66,620 KB
testcase_57 AC 247 ms
66,560 KB
testcase_58 AC 251 ms
66,600 KB
testcase_59 AC 244 ms
66,544 KB
testcase_60 AC 249 ms
66,544 KB
testcase_61 AC 252 ms
66,680 KB
testcase_62 AC 245 ms
66,564 KB
testcase_63 AC 246 ms
66,612 KB
testcase_64 AC 239 ms
66,604 KB
testcase_65 AC 241 ms
66,884 KB
testcase_66 AC 240 ms
66,672 KB
testcase_67 AC 240 ms
66,612 KB
testcase_68 AC 242 ms
66,568 KB
testcase_69 AC 243 ms
66,548 KB
testcase_70 AC 247 ms
66,616 KB
testcase_71 AC 247 ms
66,592 KB
testcase_72 AC 241 ms
66,572 KB
testcase_73 AC 243 ms
66,548 KB
testcase_74 AC 236 ms
66,544 KB
testcase_75 AC 241 ms
66,596 KB
testcase_76 AC 256 ms
66,836 KB
testcase_77 AC 250 ms
66,596 KB
testcase_78 AC 253 ms
66,556 KB
testcase_79 AC 250 ms
66,556 KB
testcase_80 AC 250 ms
66,544 KB
testcase_81 AC 249 ms
66,612 KB
testcase_82 AC 249 ms
66,556 KB
testcase_83 AC 250 ms
66,560 KB
testcase_84 AC 256 ms
66,672 KB
testcase_85 AC 255 ms
66,552 KB
testcase_86 AC 250 ms
66,544 KB
testcase_87 AC 246 ms
66,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>

using namespace std;

const long long THR = 1000000000000LL;

long long solve(const map<long long, int>& mp, long long value, long long lower){
    auto it = mp.find(value);
    if(it != mp.end() && it->second > lower) return it->second;
    if(value-1 > lower) return value-1;
    return 1LL << 60;
}

int main(){
    map<long long, int> mp;
    for(long long i=2;;i++){
        long long cur = (i+1)*i+1;
        if(cur > THR) break;
        while(cur <= THR){
            mp[cur] = i;
            cur = i*cur+1;
        }
    }
    long long N; cin >> N;
    if(N == 1 || N == 31 || N == 8192){
        cout << 2 << endl;
    } else if(N == 2){
        cout << 3 << endl;
    } else {
        long long res = solve(mp, N, 1);
        for(long long d=2;d*d<=N;d++){
            if(N%d) continue;
            res = min(solve(mp, N/d, d), res);
            res = min(solve(mp, d, N/d), res);
        }
        cout << res << endl;
    }
}
0