結果

問題 No.1666 累乗数
ユーザー rlangevinrlangevin
提出日時 2023-09-06 12:32:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 895 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 1,227 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 252,972 KB
最終ジャッジ日時 2023-09-06 12:32:39
合計ジャッジ時間 19,787 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 814 ms
252,972 KB
testcase_01 AC 861 ms
252,716 KB
testcase_02 AC 875 ms
252,652 KB
testcase_03 AC 819 ms
252,168 KB
testcase_04 AC 800 ms
252,824 KB
testcase_05 AC 772 ms
252,556 KB
testcase_06 AC 788 ms
252,500 KB
testcase_07 AC 801 ms
252,404 KB
testcase_08 AC 783 ms
252,700 KB
testcase_09 AC 895 ms
252,724 KB
testcase_10 AC 842 ms
252,824 KB
testcase_11 AC 818 ms
252,500 KB
testcase_12 AC 799 ms
252,632 KB
testcase_13 AC 808 ms
252,376 KB
testcase_14 AC 837 ms
252,748 KB
testcase_15 AC 819 ms
252,500 KB
testcase_16 AC 873 ms
252,856 KB
testcase_17 AC 882 ms
252,416 KB
testcase_18 AC 796 ms
252,628 KB
testcase_19 AC 808 ms
252,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from bisect import *

def isqrt(n):
    yes = 1
    no = 10 ** 9 + 5
    while no - yes != 1:
        mid = (yes + no)//2
        if mid * mid <= n:
            yes = mid
        else:
            no = mid
    return yes 

inf = 10 ** 18 + 5
S = set()
for n in range(3, 65):
    now = 2
    while True:
        v = now ** n
        if v >= inf:
            break
        v2 = isqrt(v) ** 2
        if v != v2:
            S.add(now ** n)
        now += 1
S = sorted(list(S))

T = int(input())
for _ in range(T):
    K = int(input())
    yes = inf
    no = 0
    while yes - no != 1:
        mid = (yes + no)//2
        i2 = isqrt(mid)
        ans = -1
        if i2 ** 2 == mid:
            ans = mid
        else:
            ans = (i2 + 1) ** 2
        i3over = bisect_right(S, mid)
        if i2 + i3over >= K:
            yes = mid
        else:
            no = mid
    print(yes)
0