結果
問題 |
No.186 中華風 (Easy)
|
ユーザー |
|
提出日時 | 2017-03-20 01:09:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 634 bytes |
コンパイル時間 | 1,571 ms |
コンパイル使用メモリ | 165,900 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-19 18:30:59 |
合計ジャッジ時間 | 2,241 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; ll solve(ll x1, ll y1, ll x2, ll y2, ll limit) { for (ll i = x1; i <= limit; i += y1) { if (i == 0) continue; if (i % y2 == x2) return i; } return -1; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll x[3], y[3]; for (int i = 0; i < 3; i++) cin >> x[i] >> y[i]; ll l1 = y[0] / __gcd(y[0], y[1]) * y[1]; ll ans = solve(x[0], y[0], x[1], y[1], l1); if (ans == -1) { cout << -1 << endl; return 0; } ll l2 = l1 / __gcd(l1, y[2]) * y[2]; ans = solve(ans % l1, l1, x[2], y[2], l2); cout << ans << endl; return 0; }