結果

問題 No.800 四平方定理
ユーザー tobusakanatobusakana
提出日時 2022-10-02 17:21:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,689 ms / 2,000 ms
コード長 601 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 326,556 KB
最終ジャッジ日時 2023-08-26 15:21:14
合計ジャッジ時間 24,407 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
78,820 KB
testcase_01 AC 113 ms
82,060 KB
testcase_02 AC 110 ms
79,916 KB
testcase_03 AC 115 ms
80,376 KB
testcase_04 AC 111 ms
80,284 KB
testcase_05 AC 114 ms
81,488 KB
testcase_06 AC 117 ms
82,508 KB
testcase_07 AC 120 ms
84,908 KB
testcase_08 AC 126 ms
88,356 KB
testcase_09 AC 114 ms
81,676 KB
testcase_10 AC 726 ms
202,628 KB
testcase_11 AC 715 ms
198,880 KB
testcase_12 AC 820 ms
229,936 KB
testcase_13 AC 591 ms
157,480 KB
testcase_14 AC 623 ms
167,876 KB
testcase_15 AC 817 ms
221,100 KB
testcase_16 AC 652 ms
170,528 KB
testcase_17 AC 623 ms
170,516 KB
testcase_18 AC 1,108 ms
238,376 KB
testcase_19 AC 1,474 ms
239,492 KB
testcase_20 AC 92 ms
71,692 KB
testcase_21 AC 95 ms
71,492 KB
testcase_22 AC 1,226 ms
239,564 KB
testcase_23 AC 1,684 ms
326,556 KB
testcase_24 AC 1,449 ms
268,960 KB
testcase_25 AC 1,689 ms
307,960 KB
testcase_26 AC 86 ms
71,880 KB
testcase_27 AC 85 ms
71,908 KB
testcase_28 AC 1,195 ms
269,232 KB
testcase_29 AC 1,439 ms
261,040 KB
testcase_30 AC 1,359 ms
273,212 KB
testcase_31 AC 1,099 ms
242,904 KB
testcase_32 AC 1,300 ms
262,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,D = map(int,input().split())

from collections import defaultdict
left = defaultdict(int)
MAX = N ** 2 - 1 + D
for x in range(1, N + 1):
    for y in range(1, N + 1):
        val = x**2 + y**2
        if val > MAX:
            break
        left[x**2 + y**2] += 1
        
right = defaultdict(int)
for w in range(1, N + 1):
    for z in range(1, N + 1):
        val = w**2 - z**2 + D
        if val < 0:
            break
        right[w**2 - z**2 + D] += 1
        
ans = 0
for key, value in left.items():
    if key in right:
        ans += right[key] * value
        
print(ans)
        
        
0