結果
問題 | No.1666 累乗数 |
ユーザー |
![]() |
提出日時 | 2021-09-03 21:50:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 7,780 bytes |
コンパイル時間 | 4,550 ms |
コンパイル使用メモリ | 228,100 KB |
最終ジャッジ日時 | 2025-01-24 05:28:17 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | WA * 19 |
ソースコード
#pragma GCC optimize("Ofast")#pragma GCC optimize("unroll-loops")#pragma GCC optimize("inline")#include<bits/stdc++.h>using namespace std;template<class T> struct cLtraits_identity{using type = T;};template<class T> using cLtraits_try_make_signed =typename conditional<is_integral<T>::value,make_signed<T>,cLtraits_identity<T>>::type;template <class S, class T> struct cLtraits_common_type{using tS = typename cLtraits_try_make_signed<S>::type;using tT = typename cLtraits_try_make_signed<T>::type;using type = typename common_type<tS,tT>::type;};template<class S, class T> inline auto max_L(S a, T b)-> typename cLtraits_common_type<S,T>::type{return (typename cLtraits_common_type<S,T>::type) a >= (typename cLtraits_common_type<S,T>::type) b ? a : b;}#define ISPRIME_PRE_CALC_SIZE 1000000char isPrime_prime_table[ISPRIME_PRE_CALC_SIZE];template<class T> inline int isPrime(T n);void isPrime32_init(void);int isPrime32_sub(int b, unsigned n);int isPrime32(unsigned n);int isPrime64_sub(long long b, unsigned long long n);int isPrime64(unsigned long long n);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(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> inline T pow2_L(T a){return a*a;}template<class T, class S> inline T pow_L(T a, S b){T res = 1;res = 1;for(;;){if(b&1){res *= a;}b >>= 1;if(b==0){break;}a *= a;}return res;}inline double pow_L(double a, double b){return pow(a,b);}inline long long Isqrt_f_L(const long long n){long long r = sqrt(n);r =max_L(r-2, 0);while((pow2_L((r+1)))<= n ){r++;}return r;}long long Ikthroot(long long N, long long k){long long res;if(k==1){return N;}if(k==2){return Isqrt_f_L(N);}res = pow(N, 1.0 / k);res =max_L(res-10, 0);while((pow_L((res+1),k))<= N ){res++;}return res;}int main(){int e98WHCEY;{isPrime32_init();}int cTE1_r3A = rd_int();for(e98WHCEY=(0);e98WHCEY<(cTE1_r3A);e98WHCEY++){long long K;rd(K);long long res;long long cnt;long long k;long long xr20shxY;long long WYIGIcGE;long long t_ynMSdg;xr20shxY = 1;WYIGIcGE = 1000000000000000000LL;while(xr20shxY < WYIGIcGE){int i;if((xr20shxY + WYIGIcGE)%2==0){t_ynMSdg = (xr20shxY + WYIGIcGE) / 2;}else{t_ynMSdg = (xr20shxY + WYIGIcGE - 1) / 2;}cnt = 1;for(i=(1);i<(62);i++){if(isPrime(i)){cnt += Ikthroot(t_ynMSdg,i) - 1;}}if(cnt >= K){WYIGIcGE = t_ynMSdg;}else{xr20shxY = t_ynMSdg + 1;}}res =WYIGIcGE;wt_L(res);wt_L('\n');}return 0;}template<class T> inline int isPrime(T n){T i;if(n<=1){return 0;}if(n <= (1ULL<<32) - 1){return isPrime32(n);}if(n <= (1ULL<<63) - 1 + (1ULL<<63)){return isPrime64(n);}if(n<=3){return 1;}if(n%2==0){return 0;}for(i=3;i*i<=n;i+=2){if(n%i==0){return 0;}}return 1;}int isPrime32_sub(int b, unsigned n){unsigned i;unsigned t = 0;unsigned u = n-1;unsigned long long nw;unsigned long long nx;while(!(u&1)){t++;u >>= 1;}nw = 1;nx = b % n;while(u){if(u&1){nw = (nw * nx) % n;}nx = (nx * nx) % n;u >>= 1;}for(i=(0);i<(t);i++){nx = (nw * nw) % n;if(nx == 1 && nw != 1 && nw != n-1){return 0;}nw = nx;}if(nw == 1){return 1;}return 0;}int isPrime32(unsigned n){if(n < 100000){return isPrime_prime_table[n];}if(n % 2 == 0){return 0;}if(!isPrime32_sub(2,n)){return 0;}if(n<=1000000){if(!isPrime32_sub(3,n)){return 0;}}else{if(!isPrime32_sub(7,n)){return 0;}if(!isPrime32_sub(61,n)){return 0;}}return 1;}int isPrime64_sub(long long b, unsigned long long n){unsigned long long i;unsigned long long t = 0;unsigned long long u = n-1;__uint128_t nw;__uint128_t nx;while(!(u&1)){t++;u >>= 1;}nw = 1;nx = b % n;while(u){if(u&1){nw = (nw * nx) % n;}nx = (nx * nx) % n;u >>= 1;}for(i=(0);i<(t);i++){nx = (nw * nw) % n;if(nx == 1 && nw != 1 && nw != n-1){return 0;}nw = nx;}if(nw == 1){return 1;}return 0;}int isPrime64(unsigned long long n){if(n < 100000){return isPrime_prime_table[n];}if(n < (1ULL<<32)){return isPrime32(n);}if(n % 2 == 0){return 0;}if(!isPrime64_sub(2,n)){return 0;}if(n <= 21652684502221ULL){if(!isPrime64_sub(1215,n)){return 0;}if(!isPrime64_sub(34862,n)){return 0;}if(!isPrime64_sub(574237825,n)){return 0;}}else{if(!isPrime64_sub(325,n)){return 0;}if(!isPrime64_sub(9375,n)){return 0;}if(!isPrime64_sub(28178,n)){return 0;}if(!isPrime64_sub(450775,n)){return 0;}if(!isPrime64_sub(9780504,n)){return 0;}if(!isPrime64_sub(1795265022,n)){return 0;}}return 1;}void isPrime32_init(void){int i;int j;int k;k =Isqrt_f_L(ISPRIME_PRE_CALC_SIZE);for(i=(2);i<(ISPRIME_PRE_CALC_SIZE);i++){isPrime_prime_table[i] = 1;}for(i=(2);i<(k+1);i++){if(isPrime_prime_table[i]){for(j=(i*i);j<(ISPRIME_PRE_CALC_SIZE);j+=(i)){isPrime_prime_table[j] = 0;}}}}// cLay version 20210819-1 [beta]// --- original code ---// ll Ikthroot(ll N, ll k){// ll res;// if(k==1) return N;// if(k==2) return Isqrt_f(N);// res = pow(N, 1.0 / k);// res = max(res-10, 0);// while( (res+1) ** k <= N ) res++;// return res;// }//// {// REP(rd_int()){// ll @K, res, cnt, k;// res = bsearch_min[ll,x,1,1d18][// cnt = 1;// rep(i,1,62) if(isPrime(i)) cnt += Ikthroot(x,i) - 1;// ](cnt >= K);// wt(res);// }// }