結果

問題 No.1666 累乗数
ユーザー XDXD
提出日時 2021-11-17 22:17:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,288 bytes
コンパイル時間 1,449 ms
コンパイル使用メモリ 166,932 KB
実行使用メモリ 6,112 KB
最終ジャッジ日時 2023-08-25 19:00:01
合計ジャッジ時間 5,380 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,968 KB
testcase_01 AC 148 ms
5,820 KB
testcase_02 AC 146 ms
5,948 KB
testcase_03 AC 148 ms
5,832 KB
testcase_04 AC 148 ms
5,956 KB
testcase_05 AC 151 ms
5,820 KB
testcase_06 AC 151 ms
5,832 KB
testcase_07 AC 145 ms
5,964 KB
testcase_08 AC 145 ms
5,788 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define forn(i,s,t) for(register int i=(s); i<=(t); ++i)
#define forl(i,s,t) for(register i64 i=(s); i<=(t); ++i)
#define form(i,s,t) for(register int i=(s); i>=(t); --i)
#define rep(i,s,t) for(register int i=(s); i<(t); ++i)
#define IT(u) for(register int i=G[u]; i; i=E[i].nxt)
using namespace std;
namespace FASTIO {
	const int SIZ = 1 << 26 | 1;
	char ibuf[SIZ], obuf[SIZ], *iS = ibuf, *iT = ibuf, *oS = obuf, *oT = obuf + SIZ - 1, qwq[60], qaq;
	#define gc() (iS == iT && (iT = (iS = ibuf) + fread(ibuf, 1, SIZ, stdin), iS == iT) ? EOF : *iS++)
	template<typename T>
	inline void Rdn(T& A) {
		register bool fl = 0;
		register char ch = gc(); A = 0;
		while(!isdigit(ch)) fl = (ch == '-'), ch = gc();
		while(isdigit(ch)) A = (A * 10) + (ch & 15), ch = gc();
		fl && (A = -A);
	}
	inline void Rdn(char& c) {while((c = gc()) == ' ' || c == '\n' || c == '\r');}
	inline void Rdn(char* s) {
		while((*s = gc()) == ' ' || *s == '\n' || *s == '\r') ;
		if(*s == EOF) return ;
		while(*s != ' ' && *s != '\n' && *s != '\r' && *s != EOF) *(++s) = gc();
		*s = 0;
	}
	template<typename T, typename ...U>
	inline void Rdn(T& A, U& ...B) {Rdn(A), Rdn(B...);}
	inline void flush() {fwrite(obuf, 1, oS - obuf, stdout), oS = obuf;}
	inline void pc(char c) {*oS ++ = c; if(oS == oT) flush();}
	template<typename T>
	inline void Wtn(T A) {
		if(!A) return pc('0'); if(A < 0) pc('-'), A = -A;
		while(A) qwq[++qaq] = A % 10 + '0', A /= 10;
		while(qaq) pc(qwq[qaq -- ]);
	}
	inline void Wtn(char A) {pc(A);}
	inline void Wtn(char *s) {while(*s) pc(*s), ++s;}
	inline void Wtn(const char *s) {while(*s) pc(*s), ++s;}
	template<typename T, typename ...U>
	inline void Wtn(T A, U ...B) {Wtn(A), Wtn(B...);}
#undef gc
}
using FASTIO :: Rdn;
using FASTIO :: Wtn;
using FASTIO :: flush;
typedef long long i64;
typedef double f64;
typedef unsigned long long u64;
typedef pair<i64, i64> pii;
typedef pair<int, u64> piu;
const int N = 100;
const i64 INF = 1e18;
inline void init() {}
int p[N], mu[N], tot; bool v[N];
inline void table(int lim = 63) {
	mu[1] = 1;
	forn(i, 2, lim) {
		if (!v[i]) p[++tot] = i, mu[i] = -1;
		for (int j = 1; j <= tot && i * p[j] <= lim; ++j) {
			v[i * p[j]] = 1;
			if (i % p[j]) mu[i * p[j]] = mu[i] * mu[p[j]];
			else {mu[i * p[j]] = 0; break ; }
		}
	}
}
i64 K;
inline i64 q_pow(i64 p, int k) {
	i64 res = 1;
	for (; k; k >>= 1, p *= p) (k & 1) && (res *= p);
	return res;
}
inline i64 check(i64 mid) {
	if (mid == 1) return 1;
	i64 res = 1 - mu[2] * ((i64)sqrtl(mid) - 1); // Wtn(mid, ":: ");
	forn (i, 3, 60) {
		i64 l = 1, r = ceill(pow(mid, (f64)1.0 / (i))), kk = l;
		while (l <= r) {
//			printf("[%lld, %lld]\n", l, r);
			i64 mi = l+r >> 1;
			if (q_pow(mi, i) <= mid) kk = mi, l = mi + 1;
			else r = mi - 1; 
		}
//		Wtn(kk, " \n"[i == 60]);
//		printf("%lld%c", kk, " \n"[i == 60]);
		res += -mu[i] * (kk - 1);// Wtn((i64)floorl(pow(mid, (f64)1.0 / i)), " \n"[i == 60]);
	}
	return res;
}
inline void solve() {
	Rdn(K); 
	i64 l = 1, r = 1e18, res = -1;
	while (l <= r) {
		i64 mid = l+r >> 1;
		if (check(mid) >= K) res = mid, r = mid - 1;
		else l = mid + 1;
	}
	Wtn(res, '\n');
}
int Trd;
int main() {
	Rdn(Trd); table();
//	forn (i, 1, 63) Wtn(mu[i], " \n"[i == 63]);
//	Trd = 1;
	while(Trd--) init(), solve(); flush();
	return 0;
}
0