結果
| 問題 |
No.1666 累乗数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-03 13:07:20 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 754 ms / 2,000 ms |
| コード長 | 2,044 bytes |
| コンパイル時間 | 385 ms |
| コンパイル使用メモリ | 82,712 KB |
| 実行使用メモリ | 242,696 KB |
| 最終ジャッジ日時 | 2025-05-03 13:07:39 |
| 合計ジャッジ時間 | 16,059 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 19 |
ソースコード
## https://yukicoder.me/problems/no/1666
def is_sqrt(b):
low = 0
high = 10 ** 9
while high - low > 1:
mid = (high + low) // 2
if mid ** 2 <= b:
low = mid
else:
high = mid
if high ** 2 <= b:
v = high
else:
v = low
return v ** 2 == b
def solve2(b_array, k, value):
ans = 0
if value >= b_array[0]:
low = 0
high = len(b_array) - 1
while high - low > 1:
mid = (high + low) // 2
if b_array[mid] <= value:
low = mid
else:
high = mid
if b_array[high] <= value:
ans += high + 1
else:
ans += low + 1
# 2乗のものを用意
low = 1
high = 10 ** 9
while high - low > 1:
mid = (high + low) // 2
if mid ** 2 <= value:
low = mid
else:
high = mid
if high ** 2 <= value:
ans += high
else:
ans += low
return ans >= k
def solve(b_array, k):
low = 1
high = 10 ** 18
while high - low > 1:
mid = (high + low) // 2
if solve2(b_array, k, mid):
high = mid
else:
low = mid
if solve2(b_array, k, low):
return low
else:
return high
def main():
T = int(input())
q = []
for _ in range(T):
q.append(int(input()))
# 10 ** 18 よりも小さいa^b(b>=3)を集める
b_set = set()
max_value = 10 ** 18
for b in range(3, 64):
a = 1
while a ** b <= max_value:
b_set.add(a ** b)
a += 1
# b_setの中からx^2と記述できるものは除外
b_array = []
for b in b_set:
if not is_sqrt(b):
b_array.append(b)
b_array.sort()
# 実際の回答
answers = []
for k in q:
ans = solve(b_array, k)
answers.append(ans)
for ans in answers:
print(ans)
if __name__ == "__main__":
main()