結果
| 問題 |
No.186 中華風 (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-02-02 18:58:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,642 bytes |
| コンパイル時間 | 1,920 ms |
| コンパイル使用メモリ | 168,124 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-11 09:30:32 |
| 合計ジャッジ時間 | 2,423 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (decltype(n) i = 0; i < (n); ++i)
#define rep3(i, s, n) for (decltype(n) i = (s); i < (n); ++i)
#define repR(i, n) for (decltype(n) i = (n)-1; i >= 0; --i)
#define rep3R(i, s, n) for (decltype(n) i = (n)-1; i >= (s); --i)
#define repit(it, c) for (auto it = (c).begin(); it != (c).end(); ++it)
#define all(x) ::std::begin(x), ::std::end(x)
using ll = long long;
template <typename T, typename U>
inline bool chmax(T ¤t, const U &test) {
if (current < test) {
current = test;
return true;
}
return false;
}
template <typename T, typename U>
inline bool chmin(T ¤t, const U &test) {
if (current > test) {
current = test;
return true;
}
return false;
}
const int64_t INFL = pow(10, 18);
const int INF = 2 * pow(10, 9);
ll ext_Euclid(ll a, ll b, ll &p, ll &q) {
if (b == 0) {
p = 1;
q = 0;
return a;
}
ll d = ext_Euclid(b, a % b, q, p);
q -= a / b * p;
return d;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
constexpr char endl = '\n';
///////////////////////////
vector<ll> x(3), y(3);
rep(i, 3) { cin >> x[i] >> y[i]; }
ll ans = 0;
ll mod = 1;
rep(i, 3) {
// mod p + y[i] q == gcd(mod, y[i])
ll p, q;
ll d = ext_Euclid(mod, y[i], p, q);
if ((ans - x[i]) % d != 0) {
cout << -1 << endl;
return 0;
}
ll s = (ans - x[i]) / d;
// s mod p + s y[i] q == ans - x[i]
ans = ans - mod * (s * p % (y[i] / d));
mod = mod / d * y[i];
ans = (ans % mod + mod) % mod;
}
if (ans == 0) {
ans = mod;
}
cout << ans << endl;
}