結果

問題 No.1666 累乗数
ユーザー asumo0729asumo0729
提出日時 2021-09-14 21:07:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,275 ms / 2,000 ms
コード長 1,314 bytes
コンパイル時間 626 ms
コンパイル使用メモリ 87,008 KB
実行使用メモリ 272,460 KB
最終ジャッジ日時 2023-09-09 19:53:28
合計ジャッジ時間 28,687 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,198 ms
272,080 KB
testcase_01 AC 1,215 ms
272,104 KB
testcase_02 AC 1,221 ms
272,088 KB
testcase_03 AC 1,204 ms
272,028 KB
testcase_04 AC 1,207 ms
272,208 KB
testcase_05 AC 1,216 ms
272,028 KB
testcase_06 AC 1,209 ms
272,460 KB
testcase_07 AC 1,211 ms
271,892 KB
testcase_08 AC 1,191 ms
272,132 KB
testcase_09 AC 1,194 ms
272,128 KB
testcase_10 AC 1,210 ms
272,124 KB
testcase_11 AC 1,209 ms
272,080 KB
testcase_12 AC 1,194 ms
272,176 KB
testcase_13 AC 1,239 ms
272,100 KB
testcase_14 AC 1,237 ms
272,116 KB
testcase_15 AC 1,247 ms
272,088 KB
testcase_16 AC 1,243 ms
272,232 KB
testcase_17 AC 1,261 ms
271,888 KB
testcase_18 AC 1,241 ms
272,088 KB
testcase_19 AC 1,275 ms
272,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from operator import itemgetter
from collections import defaultdict, deque
import heapq
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)

Max = 10 ** 18

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

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

ruijou_3 = set()
for j in range(3,60):
    if j & 1:
        for i in range(2, 10 ** 6 + 1):
            if i ** j > Max:
                break
            if hantei(i ** j):
                continue
            else:
                ruijou_3.add(i ** j)

ruijou_3 = list(ruijou_3)
ruijou_3.sort()
di = defaultdict(int)
index = []
for i in range(len(ruijou_3)):
    now = ruijou_3[i]
    tar = f(now) + i + 1
    index.append(tar)
    di[tar] = now
        

T = ip()

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