結果
| 問題 | No.1514 Squared Matching |
| コンテスト | |
| ユーザー |
Kiri8128
|
| 提出日時 | 2021-05-21 22:26:43 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 639 ms / 4,000 ms |
| コード長 | 720 bytes |
| 記録 | |
| コンパイル時間 | 173 ms |
| コンパイル使用メモリ | 84,992 KB |
| 実行使用メモリ | 453,760 KB |
| 最終ジャッジ日時 | 2026-04-26 11:24:30 |
| 合計ジャッジ時間 | 8,798 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
def sqrt(n):
if n == 0: return 0
x = 1 << (n.bit_length() + 1) // 2
y = (x + n // x) // 2
while y < x:
x = y
y = (x + n // x) // 2
return x
def calc(N):
nn = sqrt(N)
X = [-1] * (nn+1)
k = 2
while k <= nn:
X[k] = 1
for i in range(k*2, nn+1, k):
X[i] = 0
while k <= nn and X[k] >= 0:
k += 1
P = [i for i in range(nn + 1) if X[i] == 1]
Y = [1] * (N + 1)
Y[0] = 0
for p in P:
q = p ** 2
for i in range(N // q, 0, -1):
Y[i] += Y[i*q]
Y[i*q] = 0
# print("Y =", Y)
ans = 0
for a in Y:
ans += a ** 2
return ans
N = int(input())
print(calc(N))
Kiri8128