結果

問題 No.1666 累乗数
ユーザー ygd.ygd.
提出日時 2021-09-04 10:50:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,474 ms / 2,000 ms
コード長 1,345 bytes
コンパイル時間 1,101 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 78,492 KB
最終ジャッジ日時 2023-08-22 17:50:02
合計ジャッジ時間 21,953 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
77,088 KB
testcase_01 AC 740 ms
77,700 KB
testcase_02 AC 709 ms
77,768 KB
testcase_03 AC 705 ms
77,952 KB
testcase_04 AC 705 ms
77,972 KB
testcase_05 AC 1,474 ms
78,288 KB
testcase_06 AC 1,367 ms
78,016 KB
testcase_07 AC 1,379 ms
77,784 KB
testcase_08 AC 1,392 ms
78,260 KB
testcase_09 AC 744 ms
78,008 KB
testcase_10 AC 754 ms
77,984 KB
testcase_11 AC 750 ms
77,980 KB
testcase_12 AC 743 ms
77,988 KB
testcase_13 AC 1,217 ms
78,132 KB
testcase_14 AC 1,209 ms
78,136 KB
testcase_15 AC 1,204 ms
78,492 KB
testcase_16 AC 1,189 ms
78,144 KB
testcase_17 AC 875 ms
77,804 KB
testcase_18 AC 974 ms
78,292 KB
testcase_19 AC 855 ms
77,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
import math

L = [0]*60 #これをしないとTLE.
for i in range(2,60):
    L[i] = int(((10**18) ** (1/i)))
    L[i] += 2 #ここで余分を持ちすぎるとPowの計算の時に大きくなりすぎてTLEするっぽい。

def main():
    T = int(input())
    for _ in range(T):
        k = int(input())
        ng = 0
        ok = pow(10,18) + 10
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if check(mid) >= k:
                ok = mid
            else:
                ng = mid
        print(ok)

def check(n): #n以下の累乗数の個数
    cnt = [0]*60 #i乗と書けるものの個数。
    for i in reversed(range(2,60)):
        #同じ値でもiが大きいほうでカウント。
        #小さいほうでカウントする約数でみないといけない。
        #大きいほうに寄せると、倍数でみることができる。
        ok = 0 
        ng = L[i]
        while abs(ok - ng) > 1:
            mid = (ok+ng) // 2
            if pow(mid,i) <= n:
                ok = mid
            else:
                ng = mid
        ok -= 1 #1を除く
        cnt[i] = ok - sum(cnt[::i]) #iの倍数は全て上でそこでカウントされている。
    return sum(cnt) + 1 #除かれた1を足す


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