結果

問題 No.1666 累乗数
ユーザー asumo0729asumo0729
提出日時 2021-09-05 15:53:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,326 ms / 2,000 ms
コード長 1,314 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 87,288 KB
実行使用メモリ 282,120 KB
最終ジャッジ日時 2023-08-23 14:14:32
合計ジャッジ時間 29,485 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,308 ms
281,588 KB
testcase_01 AC 1,303 ms
281,816 KB
testcase_02 AC 1,299 ms
281,632 KB
testcase_03 AC 1,292 ms
281,820 KB
testcase_04 AC 1,297 ms
282,120 KB
testcase_05 AC 1,300 ms
281,720 KB
testcase_06 AC 1,298 ms
281,772 KB
testcase_07 AC 1,299 ms
281,960 KB
testcase_08 AC 1,298 ms
281,628 KB
testcase_09 AC 1,292 ms
282,020 KB
testcase_10 AC 1,286 ms
281,752 KB
testcase_11 AC 1,283 ms
281,264 KB
testcase_12 AC 1,311 ms
281,580 KB
testcase_13 AC 1,310 ms
281,552 KB
testcase_14 AC 1,277 ms
281,184 KB
testcase_15 AC 1,288 ms
282,112 KB
testcase_16 AC 1,312 ms
281,320 KB
testcase_17 AC 1,311 ms
281,692 KB
testcase_18 AC 1,295 ms
281,528 KB
testcase_19 AC 1,326 ms
281,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from operator import itemgetter
from collections import defaultdict
import bisect
stdin=sys.stdin
sys.setrecursionlimit(10 ** 8)

ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
Yp=lambda:print('Yes')
Np=lambda:print('No')
inf = 1 << 60
eps = 1e-9
sortkey = itemgetter(0)

def hantei(x):
    y = int(x ** (1/2))
    return y * y == x

def f(x):
    ok = 1
    ng = 10 ** 9 + 1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if mid * mid > x:
            ng = mid
        else:
            ok = mid
    return ok

T = ip()

Max = 10 ** 18
rui = set()
## **3~を考える
## 2 ** 60 > 10 ** 18なので考える累乗はたかだか59かつ奇数
for i in range(3, 60):
    if i & 1:
        for j in range(1,10 ** 6 + 1):
            if j ** i > Max:
                break
            if hantei(j):
                continue
            rui.add(j ** i)

rui = list(rui)
rui.sort()
L = len(rui)
ind = [0 for _ in range(L)]
de = defaultdict(int)
for i in range(L):
    tar = f(rui[i])
    ind[i] = tar + i + 1
    de[tar + i + 1] = rui[i]


for _ in range(T):
    K = ip()
    if de[K] != 0:
        ans = de[K]
    else:
        now = bisect.bisect_left(ind, K)
        ans = (K - now) ** 2
    print(ans)
0