結果
問題 |
No.186 中華風 (Easy)
|
ユーザー |
|
提出日時 | 2023-11-08 18:40:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 853 bytes |
コンパイル時間 | 2,161 ms |
コンパイル使用メモリ | 197,628 KB |
最終ジャッジ日時 | 2025-02-17 20:08:51 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 WA * 7 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; namespace Lib{ ll extGCD(ll a, ll b, ll &x, ll &y){ if(b==0){ x=1,y=0; return a; } ll d=extGCD(b,a%b,y,x); y=y-a/b*x; return d; } } namespace Lib{ pair<ll,ll> crt(vector<ll> r,vector<ll>m){ assert(r.size()==m.size()); ll ret_r=r[0],ret_m=m[0]; int n=r.size(); for(int i=1;i<n;i++){ ll x=0,y=0,d=extGCD(ret_m,m[i],x,y); if((ret_r-r[i])%d!=0){ return make_pair(-1ll,-1ll); } ret_r+=x*(r[i]-ret_r)/d%(m[i]/d)*ret_m; ret_m*=m[i]/d; ret_r%=ret_m; } return make_pair(ret_r,ret_m); } } // namespace Lib int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); vector r(3,0ll),m(3,0ll); for(int i=0;i<3;i++){ cin>>r[i]>>m[i]; } auto [ans,l]=Lib::crt(r,m); if(ans==0)ans=l; cout<<ans<<'\n'; }