結果
問題 | No.1255 ハイレーツ・オブ・ボリビアン |
ユーザー |
![]() |
提出日時 | 2024-04-13 14:54:29 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,318 bytes |
コンパイル時間 | 2,234 ms |
コンパイル使用メモリ | 203,020 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-03 00:08:46 |
合計ジャッジ時間 | 2,953 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 1 WA * 14 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } long long pow_mod(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n % 2 == 1) { res = res * a % mod; } a = a * a % mod; n /= 2; } return res; } int main() { fast_io(); int t; cin >> t; for (; t--;) { int n; cin >> n; vector<int> pf; int n_tmp = 2 * n - 1; for (int i = 2; i * i <= n_tmp; i++) { while (n_tmp % i == 0) { pf.push_back(i); n_tmp /= i; } } if (n_tmp > 1) { pf.push_back(n_tmp); } int phi = 2 * n - 1; for (int p : pf) { phi = phi / p * (p - 1); } vector<int> fac; for (int i = 1; i * i <= phi; i++) { if (phi % i == 0) { fac.push_back(i); if (i * i != phi) { fac.push_back(phi / i); } } } int ans = 2e9; for (int a : fac) { if (pow_mod(2, a, 2 * n - 1) == 1) { ans = min(ans, a); } } cout << ans << "\n"; } }