結果
問題 |
No.2406 Difference of Coordinate Squared
|
ユーザー |
|
提出日時 | 2023-07-14 00:50:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 948 ms / 2,000 ms |
コード長 | 803 bytes |
コンパイル時間 | 313 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 79,616 KB |
最終ジャッジ日時 | 2024-11-26 18:00:54 |
合計ジャッジ時間 | 18,136 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 55 |
ソースコード
import math P=998244353 n,m=map(int,input().split()) m=abs(m) fact=[1 for i in range(n+1)] fact_inv=[1 for i in range(n+1)] for i in range(2,n+1): fact[i]=(fact[i-1]*i)%P fact_inv[i]=(fact_inv[i-1]*pow(i,P-2,P))%P ans=0 for y in range(0,n+1): x=int(math.sqrt(y*y+m)) if x+y>n: break if x*x-y*y!=m: continue if (n-x-y)%2: continue a=x+(n-x-y)//2 b=(n-x-y)//2 if a>n: continue tmp=fact[n] tmp*=fact_inv[a] tmp%=P tmp*=fact_inv[n-a] tmp%=P tmp*=fact[n] tmp%=P tmp*=fact_inv[b] tmp%=P tmp*=fact_inv[n-b] tmp%=P if x and y: ans+=4*tmp ans%=P elif x or y: ans+=2*tmp ans%=P else: ans+=tmp ans%=P ans*=pow(4,n*(P-2),P) ans%=P print(ans)