結果
| 問題 |
No.1666 累乗数
|
| コンテスト | |
| ユーザー |
asumo0729
|
| 提出日時 | 2021-09-14 21:07:17 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,216 ms / 2,000 ms |
| コード長 | 1,314 bytes |
| コンパイル時間 | 283 ms |
| コンパイル使用メモリ | 82,688 KB |
| 実行使用メモリ | 271,616 KB |
| 最終ジャッジ日時 | 2024-06-27 12:28:27 |
| 合計ジャッジ時間 | 26,059 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 19 |
ソースコード
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)
asumo0729