結果
| 問題 |
No.186 中華風 (Easy)
|
| コンテスト | |
| ユーザー |
goodbaton
|
| 提出日時 | 2018-12-07 11:49:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,394 bytes |
| コンパイル時間 | 818 ms |
| コンパイル使用メモリ | 98,832 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-14 03:18:32 |
| 合計ジャッジ時間 | 1,656 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 WA * 2 |
ソースコード
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <cassert>
typedef long long ll;
using namespace std;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010
// {a, {b, c}} : a = gcd(p, q) = bp + cq
pair<ll,pair<ll,ll>> ext_gcd(ll p, ll q) {
if (q == 0) return {p, {1, 0}};
auto r = ext_gcd(q, p%q);
return {r.first, {r.second.second, r.second.first - p/q*r.second.second}};
}
/* 中国剰余定理 */
pair<ll,ll> CRT(ll a1, ll m1, ll a2, ll m2){
auto eg = ext_gcd(m1, m2);
ll d = eg.first;
if((a2 - a1) % d) return {0, -1};
ll m = m1 / d * m2;
ll p = eg.second.first; //(eg.second.first + m) % m;
ll r = ((a1 + m1 * ((a2 - a1) / d * p % (m2/d))) % m + m) % m;
return {r, m};
}
int main(){
ll r = 0, m = 1;
for(int i=0;i<3;i++){
int x, y;
cin >> x >> y;
auto res = CRT(r, m, x, y);
r = res.first;
m = res.second;
if(m == -1){
puts("-1");
return 0;
}
}
cout << r << endl;
return 0;
}
goodbaton