結果
| 問題 |
No.1022 Power Equation
|
| コンテスト | |
| ユーザー |
mkawa2
|
| 提出日時 | 2021-04-07 10:24:35 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 2,000 ms |
| コード長 | 1,537 bytes |
| コンパイル時間 | 331 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-06-22 05:03:28 |
| 合計ジャッジ時間 | 1,084 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 |
ソースコード
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)
mkawa2