結果

問題 No.358 も~っと!門松列
ユーザー hanorverhanorver
提出日時 2016-04-17 22:39:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 855 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 57,380 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 02:20:31
合計ジャッジ時間 1,237 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<algorithm>

template <typename T>
bool isKadomatsu(T a, T b, T c) {
	if (a == b || a == c || b == c) return false;
	T max = std::max(a, std::max(b, c));
	T min = std::min(a, std::min(b, c));

	if (max == b || min == b) return true;
	return false;
}

int main() {
	int a1, a2, a3;
	
	std::cin >> a1 >> a2 >> a3;

	// すでに門松列の場合は無限に答えが存在する
	if (isKadomatsu(a1, a2, a3)) {
		std::cout << "INF" << std::endl;
		return 0;
	}
	
	// 同じ値が存在するならどうやっても門松列にならない
	if (a1 == a2 || a1 == a3 || a2 == a3) {
		std::cout << 0 << std::endl;
		return 0;
	}

	int loop = std::max(a1, std::max(a2, a3));

	int ans = 0;
	for (int i = 1; i <= loop; i++) {
		if (isKadomatsu(a1 % i, a2 % i, a3 % i)) {
			ans++;
		}
	}

	std::cout << ans << std::endl;
	return 0;
}
0