結果

問題 No.1022 Power Equation
ユーザー ayaoniayaoni
提出日時 2020-11-21 13:44:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 262 ms / 2,000 ms
コード長 872 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 82,072 KB
最終ジャッジ日時 2023-09-30 21:49:47
合計ジャッジ時間 2,362 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,932 KB
testcase_01 AC 74 ms
71,836 KB
testcase_02 AC 85 ms
76,516 KB
testcase_03 AC 101 ms
76,904 KB
testcase_04 AC 176 ms
82,072 KB
testcase_05 AC 246 ms
80,888 KB
testcase_06 AC 242 ms
81,324 KB
testcase_07 AC 262 ms
82,036 KB
testcase_08 AC 134 ms
79,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from math import gcd
def I(): return int(sys.stdin.readline().rstrip())


def lcm(a,b):
    return a*b//gcd(a,b)


def f(N):
    res = 2*N**2-N
    M = int(N**.5)
    flag = [1]*(M+1)  # flag[i] == 1 ⇔ iが冪乗数でない
    for i in range(2,M+1):
        if flag[i] == 0:
            continue
        x = i**2
        while x <= M:
            flag[x] = 0
            x *= i
    for a in range(2,M+1):
        if flag[a] == 0:
            continue
        e = 2
        while a**e <= N:
            res += 2*(N//e)
            e += 1
    for aa in range(2,M+1):
        if flag[aa] == 0:
            continue
        m = 2
        while aa**m <= N:
            e = m+1
            while aa**e <= N:
                res += 2*(N*m//lcm(m,e))
                e += 1
            m += 1
    return res


T = I()
for _ in range(T):
    N = I()
    print(f(N))
0