結果
| 問題 |
No.186 中華風 (Easy)
|
| コンテスト | |
| ユーザー |
nikutto_
|
| 提出日時 | 2019-10-27 20:39:22 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 950 bytes |
| コンパイル時間 | 1,794 ms |
| コンパイル使用メモリ | 160,840 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-14 21:06:13 |
| 合計ジャッジ時間 | 2,255 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 WA * 11 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll extGcd(ll a,ll b,ll& p,ll &q){
if(b==0) {p=1; q=0; return a;}
ll d = extGcd(b,a%b,q,p);
q -= a/b * p;
return d;
}
// return minimum x s.t. x>=0 and x=b0 (mod m0) and x=b1 (mod m1)
// if such x don't exist, return (0,-1)
// O(log(m0)+log(m1))
// Note that the risk of overflow
pair<ll,ll> CRT(ll b0,ll m0,ll b1,ll m1){
ll p,q;
ll d = extGcd(m0,m1,p,q);
if((b1-b0)%d!=0) return make_pair(ll(0),ll(-1));
ll m = m0/d * m1;
ll tmp = (b1-b0)/d * p % (m1/d);
ll r = (b0 + m0 * tmp) % m;
return make_pair(r,m);
}
int main(){
vector<ll> x(3),y(3);
for(int i=0;i<3;i++) cin>>x[i]>>y[i];
auto ret = CRT(x[0],y[0],x[1],y[1]);
if(ret.second==-1){
cout<<-1<<endl;
return 0;
}
ret = CRT(ret.first,ret.second,x[2],y[2]);
cout<<ret.first<<endl;
return 0;
}
nikutto_