結果

問題 No.185 和風
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-19 23:36:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 644 bytes
コンパイル時間 1,242 ms
コンパイル使用メモリ 144,036 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 01:28:49
合計ジャッジ時間 2,619 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 112 ms
4,380 KB
testcase_02 AC 105 ms
4,376 KB
testcase_03 AC 111 ms
4,380 KB
testcase_04 AC 110 ms
4,380 KB
testcase_05 AC 117 ms
4,376 KB
testcase_06 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

long long gcd(long long a, long long b){
	if (b == 0) return a;
	return gcd(b, a%b);
}

int main() {
	long long X1, Y1, X2, Y2, X3, Y3;
	cin >> Y1 >> X1 >> Y2 >> X2 >> Y3 >> X3;
	long long ans = Y3;
	int count = X2 + 10000000;

	long long add = X3;

	while (count > 0){
		if (ans % X2 == Y2) break;
		ans += add;
		count--;
	}
	if (count <= 0){
		cout << -1 << endl;
		return 0;
	}

	add = (X3 * X2) / gcd(X3, X2);

	count = X1 + 10000000;
	while (count > 0){
		if (ans % X1 == Y1) break;
		ans += add;
		count--;
	}

	if (count <= 0){
		cout << -1 << endl;
		return 0;
	}

	cout << ans << endl;
}
0