ČOKOLADA | 프로그래밍의 벗 PivotOJ
PivotOJ

ČOKOLADA

시간 제한: 1000ms메모리 제한: 128MB출처: CHC 2012 Junior Croatian Olympiad in Informatics - Exam #1BOJ 3086
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

Marin's mother bought Marin a chocolate bar with N rows and M columns. Marin knows he cannot be selfish, so he decided to split the chocolate with his friends. He will split the chocolate in such a way that he makes cuts between rows and columns of remaining bars (starting with just one bar). In the end, all the remaining bars must be square shaped, i.e. have the same number of rows and columns. He wants to share the chocolate with only his best friends so he will split it in such a way that there is a minimal number of remaining square shaped bars left. Of course, no chocolate can be wasted. 

[이미지 1]

In the pictures above, N is 3 and M is 4. First split ends up with 6 square bars and the second one with 4, which also makes the optimal cut. 

Help Marin split his chocolate bar into smallest number of square shaped bars. 

입력

In the first and only line read integers N and M (1 ≤ N, M ≤ 1000), the number of rows and columns of the chocolate bar. 

출력

In the first and only line output a single integer - the minimal number of remaining square shaped bars. 

예제

예제 1

입력
3 4
출력
4

예제 2

입력
4 4
출력
1

예제 3

입력
2 5
출력
4
코드를 제출하려면 로그인하세요.