結果
問題 | No.1514 Squared Matching |
ユーザー |
![]() |
提出日時 | 2021-05-21 22:26:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 620 ms / 4,000 ms |
コード長 | 720 bytes |
コンパイル時間 | 188 ms |
コンパイル使用メモリ | 82,260 KB |
実行使用メモリ | 454,772 KB |
最終ジャッジ日時 | 2024-10-10 09:13:21 |
合計ジャッジ時間 | 10,573 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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))