結果

問題 No.1666 累乗数
ユーザー ygd.ygd.
提出日時 2021-09-03 23:27:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,470 bytes
コンパイル時間 776 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 85,376 KB
最終ジャッジ日時 2024-05-09 07:30:42
合計ジャッジ時間 13,207 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,245 ms
84,096 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
import math

def main():
    B = set([])
    MAX = pow(10,6) + 10
    L = [2]
    for i in L:
        for x in range(2,pow(10,3) + 10):
            v = pow(x, i)
            if v <= MAX:
                B.add(v)
    #print(B)
    B = list(B); B.sort()

    #A[x]: x以下の平方数の値(ただし1を除く)
    A = [0]*MAX
    #A[1] = 1
    for i in range(2,MAX):
        if i in B:
            A[i] = A[i-1] + 1
        else:
            A[i] = A[i-1]
    #print(A[:100])

            

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



def check(x,A):
    ret = 1 #1の分
    L = [2, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 
45, 47, 49, 51, 53, 55, 57, 59]
    for i in L: #i乗根以下の素数
        if pow(2,i) > x: break
        ok  = 2
        ng = math.ceil(x ** (1/i)) + 10
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if pow(mid,i) <= x:
                ok = mid
            else:
                ng = mid
        #print(i,ok)
        if i == 2:
            ret += ok - 1
        else:
            ret += ok - 1 - A[ok]
    return ret



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