結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー data9824data9824
提出日時 2015-06-19 23:44:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 66 ms / 5,000 ms
コード長 938 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 60,468 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 10:20:22
合計ジャッジ時間 4,454 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 66 ms
4,380 KB
testcase_08 AC 65 ms
4,380 KB
testcase_09 AC 65 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 65 ms
4,376 KB
testcase_12 AC 65 ms
4,380 KB
testcase_13 AC 37 ms
4,380 KB
testcase_14 AC 65 ms
4,376 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 AC 65 ms
4,376 KB
testcase_17 AC 65 ms
4,376 KB
testcase_18 AC 65 ms
4,376 KB
testcase_19 AC 65 ms
4,380 KB
testcase_20 AC 66 ms
4,376 KB
testcase_21 AC 65 ms
4,376 KB
testcase_22 AC 65 ms
4,376 KB
testcase_23 AC 65 ms
4,376 KB
testcase_24 AC 65 ms
4,376 KB
testcase_25 AC 65 ms
4,380 KB
testcase_26 AC 65 ms
4,380 KB
testcase_27 AC 65 ms
4,376 KB
testcase_28 AC 65 ms
4,376 KB
testcase_29 AC 65 ms
4,376 KB
testcase_30 AC 66 ms
4,376 KB
testcase_31 AC 65 ms
4,376 KB
testcase_32 AC 66 ms
4,376 KB
testcase_33 AC 65 ms
4,376 KB
testcase_34 AC 65 ms
4,376 KB
testcase_35 AC 66 ms
4,376 KB
testcase_36 AC 65 ms
4,380 KB
testcase_37 AC 65 ms
4,376 KB
testcase_38 AC 66 ms
4,376 KB
testcase_39 AC 66 ms
4,376 KB
testcase_40 AC 65 ms
4,376 KB
testcase_41 AC 65 ms
4,380 KB
testcase_42 AC 66 ms
4,376 KB
testcase_43 AC 66 ms
4,376 KB
testcase_44 AC 65 ms
4,376 KB
testcase_45 AC 65 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>

using namespace std;

long long gcd(long long x, long long y) {
	do {
		if (x < y) {
			swap(x, y);
		}
		x = x % y;
	} while (x > 0LL);
	return y;
}

long long lcm(long long x, long long y) {
	return x * y / gcd(x, y);
}

int main() {
	long long t[3];
	cin >> t[0] >> t[1] >> t[2];
	long long multiple = lcm(t[0], lcm(t[1], t[2]));
	long long denominator;
	long long positions[3];
	for (denominator = min(multiple, 1000000LL); denominator >= 0; --denominator) {
		for (int i = 0; i < 3; ++i) {
			positions[i] = 2 * multiple / t[i] % (2 * denominator);
			if (positions[i] > denominator) {
				positions[i] = 2 * denominator - positions[i];
			}
		}
		if (positions[0] == positions[1] && positions[1] == positions[2]) {
			break;
		}
	}
	long long divisor = gcd(multiple, denominator);
	multiple /= divisor;
	denominator /= divisor;
	cout << multiple << "/" << denominator << endl;
	return 0;
}
0