結果

問題 No.1666 累乗数
ユーザー tamatotamato
提出日時 2021-09-03 23:24:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,166 ms / 2,000 ms
コード長 1,267 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 87,408 KB
実行使用メモリ 281,248 KB
最終ジャッジ日時 2023-08-22 01:22:43
合計ジャッジ時間 25,142 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,098 ms
280,392 KB
testcase_01 AC 1,132 ms
280,960 KB
testcase_02 AC 1,141 ms
280,616 KB
testcase_03 AC 1,136 ms
280,764 KB
testcase_04 AC 1,141 ms
280,868 KB
testcase_05 AC 1,112 ms
280,744 KB
testcase_06 AC 1,142 ms
280,816 KB
testcase_07 AC 1,141 ms
281,144 KB
testcase_08 AC 1,132 ms
281,120 KB
testcase_09 AC 1,166 ms
280,872 KB
testcase_10 AC 1,128 ms
281,248 KB
testcase_11 AC 1,160 ms
280,956 KB
testcase_12 AC 1,153 ms
280,644 KB
testcase_13 AC 1,156 ms
280,644 KB
testcase_14 AC 1,144 ms
281,140 KB
testcase_15 AC 1,132 ms
280,744 KB
testcase_16 AC 1,142 ms
280,784 KB
testcase_17 AC 1,146 ms
280,736 KB
testcase_18 AC 1,153 ms
280,540 KB
testcase_19 AC 1,138 ms
281,168 KB
権限があれば一括ダウンロードができます

ソースコード

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+x

    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)

    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+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