結果

問題 No.800 四平方定理
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-15 16:27:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 338 ms / 2,000 ms
コード長 600 bytes
コンパイル時間 1,094 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 201,332 KB
最終ジャッジ日時 2023-08-27 07:24:08
合計ジャッジ時間 7,681 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
76,728 KB
testcase_01 AC 87 ms
78,644 KB
testcase_02 AC 87 ms
78,080 KB
testcase_03 AC 88 ms
78,224 KB
testcase_04 AC 86 ms
78,000 KB
testcase_05 AC 87 ms
78,292 KB
testcase_06 AC 88 ms
79,228 KB
testcase_07 AC 90 ms
78,380 KB
testcase_08 AC 86 ms
78,836 KB
testcase_09 AC 88 ms
78,860 KB
testcase_10 AC 197 ms
138,144 KB
testcase_11 AC 199 ms
145,492 KB
testcase_12 AC 209 ms
144,336 KB
testcase_13 AC 180 ms
140,732 KB
testcase_14 AC 191 ms
145,860 KB
testcase_15 AC 208 ms
145,368 KB
testcase_16 AC 191 ms
146,356 KB
testcase_17 AC 193 ms
146,324 KB
testcase_18 AC 228 ms
145,964 KB
testcase_19 AC 226 ms
146,540 KB
testcase_20 AC 74 ms
71,548 KB
testcase_21 AC 74 ms
71,260 KB
testcase_22 AC 224 ms
146,732 KB
testcase_23 AC 338 ms
201,332 KB
testcase_24 AC 288 ms
201,308 KB
testcase_25 AC 331 ms
201,108 KB
testcase_26 AC 75 ms
71,356 KB
testcase_27 AC 75 ms
71,272 KB
testcase_28 AC 293 ms
200,644 KB
testcase_29 AC 315 ms
201,160 KB
testcase_30 AC 288 ms
200,872 KB
testcase_31 AC 276 ms
192,072 KB
testcase_32 AC 294 ms
201,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main0(n,d):
	ans=0
	for x in range(1,n+1):
		for y in range(1,n+1):
			for z in range(1,n+1):
				for w in range(1,n+1):
					if x**2+y**2+z**2==d+w**2:
						ans+=1
	return ans
# 1<=N<=2000
# 0<=D<=10**6
def main1(n,d):
	mat0=[0]*(1+2*n**2)
	for x in range(1,n+1):
		for y in range(1,n+1):
			mat0[x**2+y**2]+=1
	mat1=[0]*(1+2*n**2)
	for x in range(1,n+1):
		for y in range(1,n+1):
			if 0<d+x**2-y**2<1+2*n**2:
				mat1[d+x**2-y**2]+=1
	ans=0
	for i in range(1,1+2*n**2):
		ans+=mat0[i]*mat1[i]
	return ans

if __name__=='__main__':
	n,d=map(int,input().split())
	ret1=main1(n,d)
	print(ret1)

0