結果

問題 No.186 中華風 (Easy)
ユーザー fine
提出日時 2017-03-20 01:06:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 609 bytes
コンパイル時間 1,465 ms
コンパイル使用メモリ 166,252 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-04 23:41:02
合計ジャッジ時間 2,511 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 % 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;
}
0