뭔가 어려워 보였는데 그냥 기약분수 구하는 문제였다.
기약분수를 구하려면 분자, 분모에 최대 공약수를 나눠야 하므로 최대공약수를 구하는 부분을 추가했다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = long long;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
int GCD(int a, int b)
{
if (b == 0)
return a;
return GCD(b, a % b);
}
int main()
{
int n;
scanf("%d", &n);
vector<int> v(n);
for (int i = 0; i < n; i++)
scanf("%d", &v[i]);
for (int i = 1; i < n; i++)
{
int tmp = GCD(max(v[0], v[i]), min(v[0], v[i]));
printf("%d/%d\n", v[0] / tmp, v[i] / tmp);
}
return 0;
}
'백준' 카테고리의 다른 글
15989 1, 2, 3더하기 4 (0) | 2020.09.06 |
---|---|
1411 비슷한 단어 (0) | 2020.09.05 |
14717 앉았다 (2) | 2020.09.02 |
1064 평행사변형 (0) | 2020.08.31 |
1493 박스 채우기 (0) | 2020.08.30 |