結果

問題 No.1666 累乗数
ユーザー H3PO4
提出日時 2024-08-30 10:05:02
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,923 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 102,052 KB
最終ジャッジ日時 2024-08-30 10:05:45
合計ジャッジ時間 41,983 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import isqrt
from bisect import bisect_right

# 平方数でない累乗数を列挙

MAX = 10 ** 18
power_without_square = set()
for b in range(3, 64):
    a = 2
    while True:
        p = a ** b
        if p > MAX:
            break
        a += 1
        if isqrt(p) ** 2 == p:
            continue
        power_without_square.add(p)


power_without_square = sorted(power_without_square)

T=int(input())
for _ in range(T):
    N=int(input())

    # x以下の累乗数がいくつあるか二分探索
    l, r = 0, MAX
    while r - l > 1:
        m = (l + r) // 2
        ct = isqrt(m) + bisect_right(power_without_square, m)
        if ct >= N:
            r = m
        else:
            l = m
    print(r)
0