結果
問題 | No.186 中華風 (Easy) |
ユーザー |
|
提出日時 | 2015-04-20 00:20:45 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 1,390 bytes |
コンパイル時間 | 458 ms |
コンパイル使用メモリ | 61,872 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-19 18:23:06 |
合計ジャッジ時間 | 1,489 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <utility> using namespace std; typedef pair<long long, long long> PLL; template <class T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } int main() { long long x1, y1, x2, y2, x3, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; PLL big, small; if (y1 > y2) { big = make_pair(x1, y1); small = make_pair(x2, y2); } else { big = make_pair(x2, y2); small = make_pair(x1, y1); } long long y12 = lcm(y1, y2); long long x12 = -1; if (big.first == 0 && small.first == 0) { x12 = y12; } else { for (long long i = big.first; i <= y12; i += big.second) { if (i % small.second == small.first) { x12 = i; break; } } if (x12 == -1) { cout << -1 << endl; return 0; } } if (y12 > y3) { big = make_pair(x12, y12); small = make_pair(x3, y3); } else { big = make_pair(x3, y3); small = make_pair(x12, y12); } long long y123 = lcm(y12, y3); long long x123 = -1; if (big.first == 0 && small.first == 0) { x123 = y123; } else { for (long long i = big.first; i <= y123; i += big.second) { if (i % small.second == small.first) { x123 = i; break; } } if (x123 == -1) { cout << -1 << endl; return 0; } } cout << x123 << endl; return 0; }