結果
問題 | No.1140 EXPotentiaLLL! |
ユーザー | LayCurse |
提出日時 | 2020-07-31 21:29:02 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 77 ms / 2,000 ms |
コード長 | 3,910 bytes |
コンパイル時間 | 2,603 ms |
コンパイル使用メモリ | 211,976 KB |
実行使用メモリ | 11,904 KB |
最終ジャッジ日時 | 2024-07-06 16:26:10 |
合計ジャッジ時間 | 5,085 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
11,904 KB |
testcase_01 | AC | 49 ms
11,776 KB |
testcase_02 | AC | 52 ms
11,776 KB |
testcase_03 | AC | 50 ms
11,776 KB |
testcase_04 | AC | 44 ms
11,648 KB |
testcase_05 | AC | 62 ms
11,776 KB |
testcase_06 | AC | 59 ms
11,776 KB |
testcase_07 | AC | 77 ms
11,776 KB |
testcase_08 | AC | 15 ms
9,728 KB |
testcase_09 | AC | 14 ms
9,728 KB |
testcase_10 | AC | 14 ms
9,728 KB |
testcase_11 | AC | 15 ms
9,856 KB |
testcase_12 | AC | 15 ms
9,856 KB |
ソースコード
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; void *wmem; char memarr[96000000]; template<class S, class T> inline S min_L(S a,T b){ return a<=b?a:b; } 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); } 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'); } } int Prime_L(int N, int res[], void *mem=wmem){ int i; int a; int b; int sz = 1; const int r = 23000; bool *isprime; int *sf; int ss = 1; walloc1d(&isprime, r, &mem); walloc1d(&sf, r, &mem); isprime = (bool*)mem; sf = (int*)(isprime + r); N /= 2; res[0] = 2; b =min_L(r, N); for(i=(1);i<(b);i++){ isprime[i] = 1; } for(i=(1);i<(b);i++){ if(isprime[i]){ res[sz++] = 2*i+1; sf[ss] = 2*i*(i+1); if(sf[ss] < N){ while(sf[ss] < r){ isprime[sf[ss]] = 0; sf[ss] += res[ss]; } ss++; } } } for(a=r; a<N; a+=r){ b =min_L(a + r, N); isprime -= r; for(i=(a);i<(b);i++){ isprime[i] = 1; } for(i=(1);i<(ss);i++){ while(sf[i] < b){ isprime[sf[i]] = 0; sf[i] += res[i]; } } for(i=(a);i<(b);i++){ if(isprime[i]){ res[sz++] = 2*i+1; } } } return sz; } long long A; long long P; int ps; int p[5000000]; char isp[5000000+1]; int main(){ int Q5VJL1cS, i; wmem = memarr; ps =Prime_L(5000000,p); for(i=(0);i<(ps);i++){ isp[p[i]] = 1; } int e98WHCEY = rd_int(); for(Q5VJL1cS=(0);Q5VJL1cS<(e98WHCEY);Q5VJL1cS++){ rd(A); rd(P); if(!isp[P]){ wt_L(-1); wt_L('\n'); continue; } if(A%P==0){ wt_L(0); wt_L('\n'); } else{ wt_L(1); wt_L('\n'); } } return 0; } // cLay varsion 20200509-1 // --- original code --- // ll A, P; // int ps, p[5d6]; // char isp[5d6+1]; // { // ps = Prime(5d6,p); // rep(i,ps) isp[p[i]] = 1; // REP(rd_int()){ // rd(A,P); // if(!isp[P]) wt(-1), continue; // wt(if[A%P==0, 0, 1]); // } // }