結果

問題 No.2558 中国剰余定理
ユーザー oharuoharu
提出日時 2023-12-03 15:30:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 666 bytes
コンパイル時間 1,673 ms
コンパイル使用メモリ 167,264 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-03 15:30:29
合計ジャッジ時間 2,867 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,676 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
6,676 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,676 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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];
 cout<<x<<' '<<y<<endl;
 long long ans=p*x;
 ans%=(p*q);ans*=(b-a);ans+=a;
 ans%=(p*q);
 if(ans<0){ans+=(p*q);}
 cout<<ans<<endl;
 }
}
0