結果

問題 No.186 中華風 (Easy)
ユーザー masamasa
提出日時 2015-04-20 00:01:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,170 bytes
コンパイル時間 418 ms
コンパイル使用メモリ 62,376 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 02:10:43
合計ジャッジ時間 1,522 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 5 ms
4,380 KB
testcase_02 AC 6 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 10 ms
4,376 KB
testcase_06 AC 15 ms
4,376 KB
testcase_07 AC 9 ms
4,376 KB
testcase_08 AC 18 ms
4,380 KB
testcase_09 AC 18 ms
4,376 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 22 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 8 ms
4,380 KB
testcase_14 AC 9 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
	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;
	for (long long i = big.first; i < y123; i += big.second) {
		if (i % small.second == small.first) {
			x123 = i;
			break;
		}
	}

	cout << x123 << endl;
	return 0;
}
0