結果

問題 No.1666 累乗数
ユーザー 👑 rin204rin204
提出日時 2023-12-20 22:35:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,125 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,860 KB
最終ジャッジ日時 2023-12-20 22:35:54
合計ジャッジ時間 7,134 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,716 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
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 #

def EnumeratePrimes(n):
    if n <= 1:
        return []
    A = [1, 7, 11, 13, 17, 19, 23, 29]
    thres = (n + 29) // 30
    sieve = [255] * (thres + int(n**0.5) + 10)

    def ntoi(i):
        return (i >> 2) + (not (~i & 19))

    sieve[0] ^= 1
    i = 0
    flg = 1
    while flg:
        if sieve[i] != 0:
            for j in range(8):
                if sieve[i] >> j & 1:
                    p = i * 30 + A[j]
                    if p * p > n:
                        flg = 0
                        continue
                    q = [0] * 8
                    r = [0] * 8
                    s = 0
                    for k in range(8):
                        x = p * (i * 30 + A[k])
                        q[k] = x // 30
                        r[k] = ntoi(x - 30 * q[k])
                    while q[0] + s < thres:
                        sieve[q[0] + s] &= ~(1 << r[0])
                        sieve[q[1] + s] &= ~(1 << r[1])
                        sieve[q[2] + s] &= ~(1 << r[2])
                        sieve[q[3] + s] &= ~(1 << r[3])
                        sieve[q[4] + s] &= ~(1 << r[4])
                        sieve[q[5] + s] &= ~(1 << r[5])
                        sieve[q[6] + s] &= ~(1 << r[6])
                        sieve[q[7] + s] &= ~(1 << r[7])
                        s += p

        i += 1
    primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
    for i in range(1, thres):
        for j in range(8):
            if sieve[i] >> j & 1:
                primes.append(i * 30 + A[j])
    while primes[-1] > n:
        primes.pop()
    return primes


P = EnumeratePrimes(65)

for _ in range(int(input())):
    k = int(input())
    if k == 1:
        print(1)
        continue

    k -= 1
    l = 1
    r = 10**18
    while r - l > 1:
        cnt = 0
        m = (l + r) // 2
        for p in P:
            c = int(m ** (1 / p))
            while pow(c, p) <= m:
                c += 1
            while pow(c, p) > m:
                c -= 1
            cnt += c - 1
            if cnt >= k:
                break

        if cnt >= k:
            r = m
        else:
            l = m
    print(r)
0