結果
問題 |
No.1255 ハイレーツ・オブ・ボリビアン
|
ユーザー |
![]() |
提出日時 | 2020-10-09 21:59:53 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 908 bytes |
コンパイル時間 | 763 ms |
コンパイル使用メモリ | 67,656 KB |
最終ジャッジ日時 | 2025-01-15 04:39:36 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 5 WA * 10 |
ソースコード
#include <iostream> using namespace std; int phi(int x){ int eu = x; for(int i=2;i*i<=x;i++){ if(x%i==0){ eu /= i; eu *= (i - 1); } while(x%i==0) x /= i; } if(x!=1){ eu /= x; eu *= (x - 1); } return eu; } bool solve(int a,int x,int mod){ int ret = 1; while(x){ if(x&1) (ret *= a) %= mod; (a *= a) %= mod; x /= 2; } return ret==1; } int main(){ int t; cin >> t; while(t){ t--; int i,n; cin >> n; n = 2*n - 1; int m = phi(n); int ans = m; if(n==1){ cout << 1 << endl; }else{ for(i=1;i*i<=m;i++){ if(m%i==0){ if(solve(2,i,n)) ans = min(ans,i); if(solve(2,m/i,n)) ans = min(ans,m/i); } } cout << ans << endl; } } }