結果

問題 No.1022 Power Equation
ユーザー maspymaspy
提出日時 2020-04-10 21:37:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 865 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 10,816 KB
実行使用メモリ 29,848 KB
最終ジャッジ日時 2023-10-13 23:39:17
合計ジャッジ時間 4,537 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
29,768 KB
testcase_01 AC 138 ms
29,724 KB
testcase_02 AC 141 ms
29,660 KB
testcase_03 AC 143 ms
29,648 KB
testcase_04 AC 137 ms
29,840 KB
testcase_05 AC 135 ms
29,848 KB
testcase_06 AC 136 ms
29,688 KB
testcase_07 AC 131 ms
29,744 KB
testcase_08 AC 151 ms
29,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
import itertools

T = int(readline())
nums = np.array(read().split(), np.int64)
count = np.zeros_like(nums)

# a = c = 1
count += nums ** 2


def find_kth_root_int(a, k):
    if k == 0:
        return 0
    x = int(a ** (1 / k))
    while (x ** k > a):
        x -= 1
    while ((x + 1) ** k <= a):
        x += 1
    return x


bounds = []
for k in range(40):
    # r^k <= N となる r の最大値を求める
    R = np.array([find_kth_root_int(x, k) for x in nums], np.int64)
    bounds.append(R)

for k, l in itertools.product(range(1, 40), repeat=2):
    if np.gcd(k, l) > 1:
        continue
    cnt_r = bounds[max(k, l)] - 1
    cnt_bd = nums // max(k, l)
    count += cnt_r * cnt_bd

print('\n'.join(count.astype(str)))
0