문제

대열이는 욱제의 친구다.

  • “야 백대열을 약분하면 뭔지 알아?”
  • “??”
  • “십대일이야~ 하하!”

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

+ Recent posts