結果

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

テストケース

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

ソースコード

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