結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 711 ms
243,008 KB
testcase_01 AC 732 ms
243,228 KB
testcase_02 AC 735 ms
243,192 KB
testcase_03 AC 724 ms
243,744 KB
testcase_04 AC 738 ms
242,672 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))
        if r ** 2 > n:
            return r- 1
        if (r+1) <= n:
            return r+1
        return r

    M = 10 ** 6
    MAX = 10 ** 18
    S = {1}
    for a in range(2, M+1):
        cur = a
        for b in range(2, 61):
            cur *= a
            if cur > MAX:
                break
            S.add(cur)
    S = sorted(list(S))
    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