結果

問題 No.1666 累乗数
ユーザー とりゐとりゐ
提出日時 2022-12-21 02:11:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 644 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 77,056 KB
最終ジャッジ日時 2024-04-29 03:08:22
合計ジャッジ時間 8,268 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
60,416 KB
testcase_01 AC 101 ms
74,880 KB
testcase_02 AC 109 ms
76,160 KB
testcase_03 AC 110 ms
76,288 KB
testcase_04 AC 110 ms
76,032 KB
testcase_05 AC 642 ms
76,800 KB
testcase_06 AC 644 ms
76,416 KB
testcase_07 AC 644 ms
76,416 KB
testcase_08 AC 640 ms
76,416 KB
testcase_09 AC 199 ms
76,160 KB
testcase_10 AC 219 ms
76,672 KB
testcase_11 AC 222 ms
76,544 KB
testcase_12 AC 210 ms
76,544 KB
testcase_13 AC 513 ms
76,416 KB
testcase_14 AC 510 ms
77,056 KB
testcase_15 AC 512 ms
76,288 KB
testcase_16 AC 504 ms
76,416 KB
testcase_17 AC 313 ms
76,288 KB
testcase_18 AC 363 ms
76,672 KB
testcase_19 AC 295 ms
76,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
input=lambda :stdin.readline()[:-1]

def kth_root_int(a, k):
    assert 0 <= a and 0 < k
    if a == 0:
        return 0
    if k == 1:
        return a
    ret = int(pow(a, 1 / k))
    while pow(ret + 1, k) <= a:
        ret += 1
    while pow(ret, k) > a:
        ret -= 1
    return ret

check=[(2, -1), (3, -1), (5, -1), (6, 1), (7, -1), (10, 1), (11, -1), (13, -1), (14, 1), (15, 1), (17, -1), (19, -1), (21, 1), (22, 1), (23, -1), (26, 1), (29, -1), (30, -1), (31, -1), (33, 1), (34, 1), (35, 1), (37, -1), (38, 1), (39, 1), (41, -1), (42, -1), (43, -1), (46, 1), (47, -1), (51, 1), (53, -1), (55, 1), (57, 1), (58, 1), (59, -1)]
def count(n):
  res=-1
  for k,sgn in check:
    res-=sgn*kth_root_int(n,k)
  return res

t=int(input())
for _ in range(t):
  k=int(input())
  ng,ok=0,k**2+1
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if count(mid)>=k:
      ok=mid
    else:
      ng=mid
  print(ok)
0