結果
問題 |
No.800 四平方定理
|
ユーザー |
![]() |
提出日時 | 2025-03-20 21:08:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 228 ms / 2,000 ms |
コード長 | 648 bytes |
コンパイル時間 | 307 ms |
コンパイル使用メモリ | 82,104 KB |
実行使用メモリ | 130,716 KB |
最終ジャッジ日時 | 2025-03-20 21:08:35 |
合計ジャッジ時間 | 5,185 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
import math n, D = map(int, input().split()) max_sum_ab = 2 * n * n cnt_ab = [0] * (max_sum_ab + 1) for x in range(1, n + 1): x_sq = x * x for y in range(1, n + 1): sum_ab = x_sq + y * y if sum_ab <= max_sum_ab: cnt_ab[sum_ab] += 1 result = 0 for w in range(1, n + 1): s = w * w + D if s < 1: continue # z must be at least 1, z^2 >=1 > s when s <1, no solution z_max = min(n, math.isqrt(s)) for z in range(1, z_max + 1): z_sq = z * z target = s - z_sq if target < 0 or target > max_sum_ab: continue result += cnt_ab[target] print(result)