結果
問題 | No.2189 六平方和 |
ユーザー |
👑 ![]() |
提出日時 | 2022-12-15 23:43:31 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 659 bytes |
コンパイル時間 | 294 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 58,112 KB |
最終ジャッジ日時 | 2024-11-26 20:51:49 |
合計ジャッジ時間 | 2,391 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
def f(N):# Nを4平方和で表す O(N^2)for a in range(N+1):if 4*a*a>N: breakfor b in range(a,N+1):if a*a+3*b*b>N: breakfor c in range(b,N+1):if a*a+b*b+c*c>N: breakfor d in range(c,N+1):v=a*a+b*b+c*c+d*dif v>N: breakif v==N: return (a,b,c,d)assert 0def 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//=2print("YES")print(*ans,0,0)