結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー stoqstoq
提出日時 2020-10-10 01:02:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 924 bytes
コンパイル時間 1,845 ms
コンパイル使用メモリ 198,364 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 14:46:20
合計ジャッジ時間 2,970 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,384 KB
testcase_08 AC 42 ms
4,380 KB
testcase_09 AC 44 ms
4,380 KB
testcase_10 AC 44 ms
4,380 KB
testcase_11 AC 42 ms
4,380 KB
testcase_12 AC 43 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 95 ms
4,376 KB
testcase_15 AC 41 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

ll phi(ll n)
{
  ll res = n;
  for (ll i = 2; i * i <= n; i++)
  {
    if (n % i == 0)
    {
      res = res / i * (i - 1);
      while (n % i == 0)
        n /= i;
    }
  }
  if (n > 1)
    res = res / n * (n - 1);
  return res;
}

ll modpow(ll a, ll n, ll mod)
{
  ll p = a, res = 1;
  while (n)
  {
    if (n & 1)
      res = res * p % mod;
    p = p * p % mod;
    n >>= 1;
  }
  return res;
}

void solve()
{
  ll k;
  cin >> k;
  if(k == 1)
  {
    cout << 1 << "\n";
    return;
  }
    
  ll m = 2 * k - 1;
  ll pm = phi(m);
  ll ans = 4e18;
  for (ll i = 1; i * i <= pm; i++)
  {
    if (pm % i != 0)
      continue;
    if (modpow(2, i, m) == 1)
      ans = min(ans, i);
    if (modpow(2, pm / i, m) == 1)
      ans = min(ans, pm / i);
  }
  cout << ans << "\n";
}

int main()
{
  int q;
  cin >> q;
  for (int i = 0; i < q; i++)
    solve();
}
0