結果

問題 No.1312 Snake Eyes
ユーザー trineutron
提出日時 2020-12-09 08:13:21
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 605 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 192,584 KB
最終ジャッジ日時 2025-01-16 20:39:05
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 61 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int64_t n;
    cin >> n;
    if (n <= 2) {
        cout << n + 1 << endl;
        return 0;
    }
    for (int64_t p = 2; p * p <= n; p++) {
        int64_t s = 1;
        while (s * p + 1 <= n) {
            s = s * p + 1;
        }
        if (n % s == 0 and n / s * p > n) {
            cout << p << endl;
            return 0;
        }
    }
    int64_t ans = n - 1;
    for (int64_t d = 1; d * d <= n; d++) {
        if (n % d == 0 and n / d * (n / d - 1) > n) {
            ans = n / d - 1;
        }
    }
    cout << ans << endl;
}
0