結果

問題 No.1022 Power Equation
ユーザー mkawa2mkawa2
提出日時 2021-04-07 10:24:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,537 bytes
コンパイル時間 69 ms
コンパイル使用メモリ 11,092 KB
実行使用メモリ 8,788 KB
最終ジャッジ日時 2023-09-04 05:37:38
合計ジャッジ時間 883 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,628 KB
testcase_01 AC 17 ms
8,624 KB
testcase_02 AC 17 ms
8,788 KB
testcase_03 AC 17 ms
8,708 KB
testcase_04 AC 18 ms
8,664 KB
testcase_05 AC 20 ms
8,620 KB
testcase_06 AC 21 ms
8,684 KB
testcase_07 AC 20 ms
8,728 KB
testcase_08 AC 18 ms
8,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
dij = [(0, 1), (1, 0), (1, 1), (1, -1)]
inf = 10**19
# md = 998244353
md = 10**9+7

from math import gcd

# 互いに素な(x,y)のペアが何通りあるかをmax(x,y)ごとに数えておく
# (1,1)は別に数えてあるので除く
mx = 32
mx_cnt = [0]*mx
for x in range(1, mx):
    for y in range(1, x):
        if gcd(x, y) == 1:
            mx_cnt[x] += 2

# t^x<=nとなる最大のtを求める
def cnt(x, n):
    if x == 0: return 0
    if (1 << x) > n: return 0
    l, r = 0, round(n**(1/x))+3
    while l+1 < r:
        m = (l+r)//2
        if pow(m, x) <= n: l = m
        else: r = m
    return l-1

def solve(n):
    ans = 2*n*n-n
    for x, c in enumerate(mx_cnt):
        if c == 0: continue
        # t^x<=nとkx<=nから(t,k)が何通りあるかを計算
        ans += cnt(x, n)*(n//x)*c
    print(ans)

for _ in range(II()):
    n = II()
    solve(n)
0