結果
問題 |
No.1255 ハイレーツ・オブ・ボリビアン
|
ユーザー |
|
提出日時 | 2020-10-09 22:45:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 32 ms / 2,000 ms |
コード長 | 555 bytes |
コンパイル時間 | 621 ms |
コンパイル使用メモリ | 66,032 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-23 08:44:42 |
合計ジャッジ時間 | 1,534 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 |
コンパイルメッセージ
main.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 5 | main() | ^~~~
ソースコード
#include<iostream> using namespace std; int T,N; long modpow(long a,long b,long M){return b?modpow(a*a%M,b/2,M)*(b%2?a:1)%M:1;} main() { cin>>T; for(int i=1;i<=T;i++) { cin>>N; int ans=1; int M=N=2*N-1; for(int j=2;j*j<=M;j++) { if(M%j==0) { int t=1; while(M%j==0) { M/=j; t*=j; } ans*=t-t/j; } } if(M>1)ans*=M-1; int X=ans; for(int i=1;i*i<=X;i++) { if(X%i==0) { if(ans>i&&modpow(2,i,N)==1)ans=i; if(i!=X/i&&ans>X/i&&modpow(2,X/i,N)==1)ans=X/i; } } cout<<ans<<endl; } }