結果
| 問題 |
No.280 歯車の問題(1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-01 19:37:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,489 bytes |
| コンパイル時間 | 603 ms |
| コンパイル使用メモリ | 54,620 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-14 01:58:27 |
| 合計ジャッジ時間 | 3,004 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
#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;
}