結果

問題 No.1312 Snake Eyes
ユーザー pes_magicpes_magic
提出日時 2020-12-20 19:21:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 992 bytes
コンパイル時間 812 ms
コンパイル使用メモリ 84,560 KB
実行使用メモリ 66,816 KB
最終ジャッジ日時 2024-05-07 18:17:42
合計ジャッジ時間 22,133 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 209 ms
66,688 KB
testcase_01 AC 213 ms
66,688 KB
testcase_02 AC 210 ms
66,688 KB
testcase_03 AC 216 ms
66,560 KB
testcase_04 AC 215 ms
66,688 KB
testcase_05 AC 215 ms
66,560 KB
testcase_06 AC 213 ms
66,688 KB
testcase_07 AC 221 ms
66,560 KB
testcase_08 AC 214 ms
66,688 KB
testcase_09 AC 213 ms
66,560 KB
testcase_10 AC 222 ms
66,688 KB
testcase_11 AC 213 ms
66,560 KB
testcase_12 AC 218 ms
66,560 KB
testcase_13 AC 213 ms
66,688 KB
testcase_14 AC 213 ms
66,560 KB
testcase_15 AC 218 ms
66,688 KB
testcase_16 AC 221 ms
66,688 KB
testcase_17 AC 228 ms
66,688 KB
testcase_18 AC 212 ms
66,688 KB
testcase_19 AC 215 ms
66,560 KB
testcase_20 AC 217 ms
66,560 KB
testcase_21 AC 216 ms
66,560 KB
testcase_22 AC 209 ms
66,688 KB
testcase_23 AC 217 ms
66,688 KB
testcase_24 AC 221 ms
66,688 KB
testcase_25 AC 226 ms
66,688 KB
testcase_26 AC 211 ms
66,688 KB
testcase_27 AC 219 ms
66,816 KB
testcase_28 AC 216 ms
66,688 KB
testcase_29 AC 226 ms
66,688 KB
testcase_30 AC 220 ms
66,688 KB
testcase_31 AC 221 ms
66,688 KB
testcase_32 AC 226 ms
66,560 KB
testcase_33 AC 215 ms
66,560 KB
testcase_34 AC 212 ms
66,560 KB
testcase_35 AC 215 ms
66,688 KB
testcase_36 AC 213 ms
66,688 KB
testcase_37 AC 217 ms
66,560 KB
testcase_38 AC 222 ms
66,816 KB
testcase_39 AC 217 ms
66,560 KB
testcase_40 AC 220 ms
66,816 KB
testcase_41 AC 212 ms
66,816 KB
testcase_42 AC 214 ms
66,688 KB
testcase_43 AC 220 ms
66,688 KB
testcase_44 AC 212 ms
66,688 KB
testcase_45 AC 231 ms
66,688 KB
testcase_46 AC 218 ms
66,560 KB
testcase_47 AC 216 ms
66,560 KB
testcase_48 AC 224 ms
66,688 KB
testcase_49 AC 220 ms
66,688 KB
testcase_50 AC 223 ms
66,560 KB
testcase_51 AC 217 ms
66,688 KB
testcase_52 AC 221 ms
66,688 KB
testcase_53 AC 226 ms
66,688 KB
testcase_54 AC 219 ms
66,688 KB
testcase_55 AC 223 ms
66,816 KB
testcase_56 AC 218 ms
66,816 KB
testcase_57 AC 217 ms
66,688 KB
testcase_58 AC 224 ms
66,688 KB
testcase_59 AC 220 ms
66,816 KB
testcase_60 AC 220 ms
66,560 KB
testcase_61 AC 231 ms
66,560 KB
testcase_62 AC 217 ms
66,560 KB
testcase_63 AC 225 ms
66,688 KB
testcase_64 AC 219 ms
66,688 KB
testcase_65 AC 227 ms
66,560 KB
testcase_66 AC 216 ms
66,688 KB
testcase_67 AC 215 ms
66,688 KB
testcase_68 AC 214 ms
66,688 KB
testcase_69 AC 215 ms
66,560 KB
testcase_70 AC 222 ms
66,688 KB
testcase_71 AC 218 ms
66,688 KB
testcase_72 AC 224 ms
66,688 KB
testcase_73 AC 213 ms
66,688 KB
testcase_74 AC 213 ms
66,688 KB
testcase_75 AC 216 ms
66,688 KB
testcase_76 AC 223 ms
66,688 KB
testcase_77 AC 220 ms
66,688 KB
testcase_78 AC 229 ms
66,688 KB
testcase_79 AC 219 ms
66,688 KB
testcase_80 AC 225 ms
66,560 KB
testcase_81 AC 228 ms
66,688 KB
testcase_82 AC 230 ms
66,688 KB
testcase_83 AC 230 ms
66,688 KB
testcase_84 AC 225 ms
66,688 KB
testcase_85 AC 227 ms
66,560 KB
testcase_86 AC 223 ms
66,688 KB
testcase_87 AC 223 ms
66,688 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