結果
問題 | No.1255 ハイレーツ・オブ・ボリビアン |
ユーザー | LayCurse |
提出日時 | 2020-10-09 22:07:54 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 5,915 bytes |
コンパイル時間 | 2,625 ms |
コンパイル使用メモリ | 216,608 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-23 08:42:44 |
合計ジャッジ時間 | 3,380 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 11 ms
5,376 KB |
testcase_09 | AC | 11 ms
5,376 KB |
testcase_10 | AC | 11 ms
5,376 KB |
testcase_11 | AC | 12 ms
5,376 KB |
testcase_12 | AC | 10 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 30 ms
5,376 KB |
testcase_15 | AC | 10 ms
5,376 KB |
ソースコード
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; void*wmem; char memarr[96000000]; template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } struct Rand{ unsigned x; unsigned y; unsigned z; unsigned w; Rand(void){ x=123456789; y=362436069; z=521288629; w=(unsigned)time(NULL); } Rand(unsigned seed){ x=123456789; y=362436069; z=521288629; w=seed; } inline unsigned get(void){ unsigned t; t = (x^(x<<11)); x=y; y=z; z=w; w = (w^(w>>19))^(t^(t>>8)); return w; } inline double getUni(void){ return get()/4294967296.0; } inline int get(int a){ return (int)(a*getUni()); } inline int get(int a, int b){ return a+(int)((b-a+1)*getUni()); } inline long long get(long long a){ return(long long)(a*getUni()); } inline long long get(long long a, long long b){ return a+(long long)((b-a+1)*getUni()); } inline double get(double a, double b){ return a+(b-a)*getUni(); } inline int getExp(int a){ return(int)(exp(getUni()*log(a+1.0))-1.0); } inline int getExp(int a, int b){ return a+(int)(exp(getUni()*log((b-a+1)+1.0))-1.0); } } ; inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void rd(long long &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline int rd_int(void){ int x; rd(x); return x; } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } inline void wt_L(long long x){ int s=0; int m=0; char f[20]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } template<class T> int Factor_L(T N, T fac[]){ T i; int sz = 0; if(N%2==0){ fac[sz] = 2; N /= 2; while(N%2==0){ N /= 2; } sz++; } for(i=3;i*i<=N;i+=2){ if(N%i==0){ fac[sz] = i; N /= i; while(N%i==0){ N /= i; } sz++; } } if(N > 1){ fac[sz] = N; sz++; } return sz; } template<class T> int Factor_L(T N, T fac[], int fs[]){ T i; int sz = 0; if(N%2==0){ fac[sz] = 2; fs[sz] = 1; N /= 2; while(N%2==0){ N /= 2; fs[sz]++; } sz++; } for(i=3;i*i<=N;i+=2){ if(N%i==0){ fac[sz] = i; fs[sz] = 1; N /= i; while(N%i==0){ N /= i; fs[sz]++; } sz++; } } if(N > 1){ fac[sz] = N; fs[sz] = 1; sz++; } return sz; } template<class T> int Divisor_L(T N, T res[], void *mem = wmem){ int i; int j; int k; int s; int sz = 0; T*fc; int*fs; int fsz; walloc1d(&fc, 100, &mem); walloc1d(&fs, 100, &mem); fsz =Factor_L(N, fc, fs); res[sz++] = 1; for(i=(0);i<(fsz);i++){ s = sz; k = s * fs[i]; for(j=(0);j<(k);j++){ res[sz++] = res[j] * fc[i]; } } sort(res, res+sz); return sz; } unsigned long long powmod(unsigned long long a, unsigned long long b, unsigned long long m){ unsigned long long r = 1; while(b){ if(b&1){ r = r * a % m; } b>>=1; a = a * a % m; } return r; } int fs; long long f[200000]; int ds; long long d[200000]; int main(){ int Lj4PdHRW; wmem = memarr; Rand rnd; int KL2GvlyY = rd_int(); for(Lj4PdHRW=(0);Lj4PdHRW<(KL2GvlyY);Lj4PdHRW++){ int i; long long N; rd(N); long long res; long long phi; if(N==1){ wt_L(1); wt_L('\n'); continue; } N = 2 * N - 1; fs =Factor_L(N, f); phi = N; for(i=(0);i<(fs);i++){ phi = phi * (f[i]-1) / f[i]; } ds =Divisor_L(phi, d); for(i=(0);i<(ds);i++){ if(powmod(2, d[i], N) == 1){ wt_L(d[i]); wt_L('\n'); break; } } } return 0; } // cLay varsion 20201003-1 // --- original code --- // int fs; ll f[2d5]; // int ds; ll d[2d5]; // { // Rand rnd; // REP(rd_int()){ // ll @N, res, phi; // if(N==1) wt(1), continue; // N = 2 * N - 1; // fs = Factor(N, f); // phi = N; // rep(i,fs) phi = phi * (f[i]-1) / f[i]; // ds = Divisor(phi, d); // rep(i,ds) if(powmod(2, d[i], N) == 1) wt(d[i]), break; // } // }