编程介的小学生 2017-05-08 16:16 采纳率: 20.5%
浏览 692
已采纳

Dividing a Chocolate

The boy and Karlsson are dividing a chocolate that the boy's parents have presented him for his birthday. A chocolate is a rectangle that consists of m × n chocolate squares, separated from each other by cutlines.

Of course, Karlsson does the dividing. First Karlsson divides the chocolate into two rectangular pieces, breaking it along some cutline. Since Karlsson wants to divide chocolate fairly, he would not be satisfied if the two pieces have different sizes. In this case he cuts away the piece equal to the smaller piece out of the larger piece, and eats it. If the pieces are still not equal, he does so again, and so on. After the pieces are finally equal, Karlsson eats one of the pieces, and the boy eats another.

Karlsson wants to make an initial cut in such a way that he would eat as much chocolate as possible. However, the boy knows that Karlsson likes chocolate very much, and he watches for the process closely. Karlsson must be very careful not to offend the boy. So he must not successively cut away and eat chocolate from the same piece --- this would seem too suspicious to the boy.

Help Karlsson to find out how much chocolate he can eat.

Input

There are mutiple cases in the input file.

Each case contains m and n (1 <= m, n <= 109 ).

There is an empty line after each case.

Output

Output one integer number --- how many chocolate squares Karlsson can eat. If Karlsson cannot divide chocolate using his method, output 0 instead.

There should be am empty line after each case.
Sample Input

6 5

Sample Output

24

  • 写回答

2条回答 默认 最新

查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?