結果

問題 No.2189 六平方和
ユーザー testestesttestestest
提出日時 2022-12-15 23:43:31
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 87,240 KB
実行使用メモリ 75,724 KB
最終ジャッジ日時 2023-08-17 20:35:46
合計ジャッジ時間 4,071 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,584 KB
testcase_01 AC 75 ms
71,508 KB
testcase_02 AC 74 ms
71,628 KB
testcase_03 AC 74 ms
71,404 KB
testcase_04 AC 74 ms
71,632 KB
testcase_05 AC 76 ms
71,588 KB
testcase_06 AC 73 ms
71,484 KB
testcase_07 AC 75 ms
71,420 KB
testcase_08 AC 76 ms
71,328 KB
testcase_09 AC 77 ms
71,340 KB
testcase_10 AC 76 ms
71,340 KB
testcase_11 AC 72 ms
71,372 KB
testcase_12 AC 75 ms
71,392 KB
testcase_13 AC 76 ms
71,592 KB
testcase_14 AC 73 ms
71,480 KB
testcase_15 AC 76 ms
71,540 KB
testcase_16 AC 77 ms
71,396 KB
testcase_17 AC 78 ms
75,368 KB
testcase_18 AC 79 ms
75,440 KB
testcase_19 AC 76 ms
75,724 KB
testcase_20 AC 78 ms
75,508 KB
testcase_21 AC 74 ms
71,484 KB
testcase_22 AC 76 ms
75,508 KB
testcase_23 AC 79 ms
75,412 KB
testcase_24 AC 72 ms
71,336 KB
testcase_25 AC 76 ms
71,464 KB
testcase_26 AC 78 ms
75,480 KB
testcase_27 AC 73 ms
71,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(N):
	# Nを4平方和で表す O(N^2)
	for a in range(N+1):
		if 4*a*a>N: break
		for b in range(a,N+1):
			if a*a+3*b*b>N: break
			for c in range(b,N+1):
				if a*a+b*b+c*c>N: break
				for d in range(c,N+1):
					v=a*a+b*b+c*c+d*d
					if v>N: break
					if v==N: return (a,b,c,d)
	assert 0

def mul(p,q,M):
	return (
		(p[0]*q[0]+p[1]*q[1]+p[2]*q[2]+p[3]*q[3])%M,
		(p[0]*q[1]-p[1]*q[0]+p[2]*q[3]-p[3]*q[2])%M,
		(p[0]*q[2]-p[1]*q[3]-p[2]*q[0]+p[3]*q[1])%M,
		(p[0]*q[3]+p[1]*q[2]-p[2]*q[1]-p[3]*q[0])%M,
	)

N,M,B=map(int,input().split())

b=f(M)
ans=(0,0,0,1)
while N:
	if N%2:
		ans=mul(ans,b,B)
	b=mul(b,b,B)
	N//=2

print("YES")
print(*ans,0,0)
0