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