문제
대열이는 욱제의 친구다.
- “야 백대열을 약분하면 뭔지 알아?”
- “??”
- “십대일이야~ 하하!”
n:m이 주어진다. 욱제를 도와주자. (...)
입력
n과 m이 :을 사이에 두고 주어진다. (1 <= n, m <= 100,000,000)
출력
두 수를 최대한으로 약분하여 출력한다.
예제 입력 1
100:10 |
예제 출력 1
10:1 |
예제 입력 2
18:24 |
예제 출력 2
3:4 |
더보기
Solution
#include<stdio.h>
int gcd(int x,int y)
{
if(x<y)
{
int temp=x;
x=y;
y=temp;
}
while(y!=0)
{
int temp=x%y;
x=y;
y=temp;
}
return x;
}
int main(void)
{
int n, m, gcd_nm;
scanf("%d:%d", &n, &m);
gcd_nm=gcd(n,m);
n/=gcd_nm;
m/=gcd_nm;
printf("%d:%d\n", n, m);
return 0;
}
728x90
'백준 알고리즘' 카테고리의 다른 글
<백준 알고리즘> 2153번: 소수 단어 (0) | 2020.10.27 |
---|---|
<백준 알고리즘> 10409번: 서버 (0) | 2020.10.27 |
<백준 알고리즘> 14652번: 나는 행복합니다~ (0) | 2020.10.27 |
<백준 알고리즘> 1592번: 영식이와 친구들 (0) | 2020.10.26 |
<백준 알고리즘> 1773번: 폭죽쇼 (0) | 2020.10.26 |