結果

問題 No.1312 Snake Eyes
ユーザー 0w10w1
提出日時 2020-12-18 12:18:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 2,242 ms
コンパイル使用メモリ 191,596 KB
最終ジャッジ日時 2025-01-17 02:52:44
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 85
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  ios::sync_with_stdio(false);

  int64_t N; { cin >> N; }

  if (N < 3) { cout << N + 1 << endl; return 0; }

  int64_t minv = N - 1; {
    for (int i = 2; (int64_t) i * i <= N; ++i) {
      int64_t n = N;
      int h = n % i;
      bool ok = true;
      for (; n; n /= i) ok &= h == n % i;
      if (ok) minv = min(minv, (int64_t) i);
      if (N % i == 0 && N / i < i - 1) minv = min(minv, (int64_t) i - 1);
      if (N % i == 0 && N / i - 1 > i) minv = min(minv, (int64_t) N / i - 1);
    }
  }

  cout << minv << endl;
}

0