結果

問題 No.1666 累乗数
ユーザー tamatotamato
提出日時 2021-09-03 23:17:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,272 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 87,396 KB
実行使用メモリ 282,972 KB
最終ジャッジ日時 2023-08-22 01:07:00
合計ジャッジ時間 25,978 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,124 ms
279,988 KB
testcase_01 AC 1,139 ms
280,076 KB
testcase_02 AC 1,150 ms
280,268 KB
testcase_03 AC 1,154 ms
280,204 KB
testcase_04 AC 1,147 ms
280,448 KB
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 #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    from bisect import bisect_left
    from math import sqrt, floor
    input = sys.stdin.readline

    def square_root(n):
        r = floor(sqrt(n))
        for x in range(3, -4, -1):
            if (r+x) ** 2 <= n:
                return r

    M = 15 * 10 ** 5
    MAX = 2 * 10 ** 18
    S_set = {1}
    for a in range(2, M+1):
        cur = a
        for b in range(2, 70):
            cur *= a
            if cur > MAX:
                break
            S_set.add(cur)
    S = sorted(list(S_set))
    kk = bisect_left(S, (M+1)**2)

    for _ in range(int(input())):
        K = int(input())
        ok = MAX
        ng = 0
        mid = (ok + ng) // 2
        while ok - ng > 1:
            r = square_root(mid)
            if r <= M:
                j = bisect_left(S, mid+1)
                if j >= K:
                    ok = mid
                else:
                    ng = mid
            else:
                k = bisect_left(S, r*r+1)
                j = bisect_left(S, mid + 1) + (r - M) - (k - kk)
                if j >= K:
                    ok = mid
                else:
                    ng = mid
            mid = (ok + ng) // 2
        print(ok)


if __name__ == '__main__':
    main()
0