結果
問題 |
No.2558 中国剰余定理
|
ユーザー |
![]() |
提出日時 | 2023-12-03 15:21:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 611 bytes |
コンパイル時間 | 1,979 ms |
コンパイル使用メモリ | 165,972 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-26 22:10:50 |
合計ジャッジ時間 | 2,697 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 WA * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int A[3000][3]; void d(int i){ int x=A[i][0]%A[i+1][0],y=A[i][0]/A[i+1][0]; A[i+2][0]=x; A[i+2][1]=A[i][1]-y*A[i+1][1]; A[i+2][2]=A[i][2]-y*A[i+1][2]; } int main() { int p,q,a,b;cin>>p>>q>>a>>b; if(p<q){swap(p,q);swap(a,b);} if(q==1){cout<<a<<endl;} else{ A[0][0]=p;A[0][1]=1;A[0][2]=0; A[1][0]=q;A[1][1]=0;A[1][2]=1; int i=0; while(A[i+1][0]!=1){ d(i);i++; } int x=A[i+1][1],y=A[i+1][2]; int ans=p*x*(b-a)+a; ans%=(p*q); if(ans<0){ans+=p*q;} cout<<ans<<endl; } }