結果

問題 No.280 歯車の問題(1)
ユーザー KlayKlay
提出日時 2017-05-01 19:37:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,489 bytes
コンパイル時間 507 ms
コンパイル使用メモリ 52,788 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-12 02:10:16
合計ジャッジ時間 4,785 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,356 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,356 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,352 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,356 KB
testcase_24 AC 1 ms
4,352 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 1 ms
4,352 KB
testcase_27 AC 2 ms
4,356 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 1 ms
4,352 KB
testcase_30 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

/*
歯車の問題(1)

2
20 40

Z1 * theta1 = Z2 * theta2 => Z1 : Z2 = theta2 : theta1

theta2 = theta1 * (Z1 / Z2)

gr = theta1 / theta2 = Z2 / Z1

3
20 40 80
1  2  3

theta2 = theta1 * (20 / 40) = 0.5 * theta1
theta3 = theta2 * (40 / 80) = 0.5 * theta2

theta3 = 0.5 * 0.5 * theta1

theta1 / theta3 = 1 / (0.5 * 0.5)
*/

class FRACTION
{
	public:
	
	unsigned long long numerator, denominator;
	
	FRACTION operator*(FRACTION frac)
	{
		FRACTION answer;
		
		answer.numerator = numerator * frac.numerator;
		answer.denominator = denominator * frac.denominator;
		
		return answer;
	}
	
	private:
	
	unsigned long long GCD(unsigned long long a, unsigned long long b)
	{
		while(a != b)
		{
			if (a < b)
			{
				b -= a;
			}
			else
			{
				a-= b;
			}
		}
		
		return a;
	}
	
	public:
	
	void reduction(void)
	{
		unsigned long long gcd = GCD(numerator, denominator);
		
		numerator = numerator / gcd;
		denominator = denominator / gcd;
	}
};

FRACTION getGR(unsigned long long N1, unsigned long long N2)
{
	FRACTION GR;
	
	GR.numerator = N2;
	GR.denominator = N1;

	return GR;
}

int main(void)
{
	FRACTION GR;
	GR.numerator = 1;
	GR.denominator = 1;

	int N;

	std::cin >> N;
	
	unsigned long long Z[N];
	
	for(int i = 0; i < N; i ++)
	{
		std::cin >> Z[i];
	}
	
	for(int i = 0; i < N - 1; i ++)
	{
		GR = GR * getGR(Z[i], Z[i + 1]);
		
		GR.reduction();
	}
	
	std::cout << GR.numerator << "/" << GR.denominator << std::endl;
	
	return 0;
}























0