結果

問題 No.1666 累乗数
ユーザー asumo0729asumo0729
提出日時 2021-09-05 15:49:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,298 bytes
コンパイル時間 694 ms
コンパイル使用メモリ 86,904 KB
実行使用メモリ 270,096 KB
最終ジャッジ日時 2023-08-23 14:14:00
合計ジャッジ時間 24,604 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,079 ms
269,744 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
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 #

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 = []
## **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.append(j ** i)

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