結果

問題 No.800 四平方定理
ユーザー 💕💖💞
提出日時 2019-05-11 19:08:50
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 483 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 82,120 KB
実行使用メモリ 499,176 KB
最終ジャッジ日時 2024-07-02 01:18:08
合計ジャッジ時間 21,678 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 TLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

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


cnt1 = {}
for n1 in range(1, N+1):
    for n2 in range(1, N+1):
        v = n1**2 + n2**2
        if cnt1.get(v) is None:
            cnt1[v] = 0
        cnt1[v] += 1

cnt2 = {}
for n1 in range(1, N+1):
    for n2 in range(1, N+1):
        v = n1**2 - n2**2 + D
        if cnt2.get(v) is None:
            cnt2[v] = 0
        cnt2[v] += 1

same_keys = set(cnt1) & set(cnt2)
r = 0
for k in same_keys:
    r += cnt1[k] * cnt2[k]

print(r)
0