結果

問題 No.800 四平方定理
コンテスト
ユーザー 回転
提出日時 2025-10-16 23:30:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,950 ms / 2,000 ms
コード長 497 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 82,648 KB
実行使用メモリ 222,268 KB
最終ジャッジ日時 2025-10-16 23:31:11
合計ジャッジ時間 22,605 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

def main():
	N,D = list(map(int,input().split()))
	
	d1 = defaultdict(int)
	for x in range(1,N+1):
	    x2 = x*x
	    for y in range(1,N+1):
	        y2 = y*y
	        d1[x2+y2] += 1
	
	d2 = defaultdict(int)
	for w in range(1,N+1):
	    w2 = w*w
	    for z in range(1,N+1):
	        z2 = z*z
	        if(w2+D-z2 <= 0):break
	        if(w2+D-z2 not in d1):continue
	        d2[w2+D-z2] += 1
	
	ans = 0
	for i in d2:
	    ans += d1[i] * d2[i]
	print(ans)

main()
0