import java.util.Scanner;
public class homework {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
Scanner sc2= new Scanner(System.in);
int b = sc.nextInt();
int res = 0;
if(a>b)
{
for(int i=1; i<=b; i++)
{
if(a%b == 0)
{
System.out.println(b);
return;
}
else if(a%b != 0)
{
if(b%i == 0)
{
if(a%i == 0)
{
res = i;
}
}
}
}
System.out.println(res);
}
else if(a<b)
{
for(int i=1; i<=a; i++)
{
if(b%a == 0)
{
System.out.println(a);
return;
}
else if(b%a != 0)
{
if(a%i == 0)
{
if(b%i == 0)
{
res = i;
}
}
}
}
System.out.println(res);
}
else
{
System.out.println(a);
}
}
}
'공부' 카테고리의 다른 글
| (오일러 4번)세자리 수를 곱해 만들 수 있는 가장 큰 대칭수 (0) | 2017.03.27 |
|---|---|
| (오일러 3번)가장 큰 소인수 구하기 (0) | 2017.03.27 |
| (오일러 2번)피보나치 수열에서 4백만 이하이면서 짝수인 항의 합 (0) | 2017.03.27 |
| (오일러 1번)1000보다 작은 자연수 중에서 3 또는 5의 배수를 모두 더하면? (0) | 2017.03.27 |
| 아스키코드 증가를 이용한 알파벳 출력 (0) | 2017.03.25 |
댓글