-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
executable file
·60 lines (45 loc) · 1.01 KB
/
Copy pathsol.cpp
File metadata and controls
executable file
·60 lines (45 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
using namespace std;
struct fraction
{
long long num;
long long denom;
fraction(long long _num, long long _denom) : num(_num), denom(_denom)
{
long long gcd = __gcd(num, denom);
if (gcd != 1)
{
num /= gcd;
denom /= gcd;
}
}
fraction operator*(fraction other)
{
return {num * other.num, denom * other.denom};
}
friend ostream &operator<<(ostream &os, fraction &f)
{
os << f.num << "/" << f.denom;
return os;
}
};
int main()
{
int n;
cin >> n;
vector<int> V(n);
for (int i = 0; i < n; ++i)
cin >> V[i];
vector<fraction> fracs;
for (int i = 0; i < n - 1; ++i)
fracs.push_back(fraction(V[i], V[i + 1]));
for (int i = 1; i < fracs.size(); ++i)
{
fraction prev = fracs[i - 1];
fraction curr = fracs[i];
fracs[i] = prev * curr;
}
for (auto f : fracs)
cout << f << endl;
return 0;
}