Category: Algorithms
Title: Dividing a Chocolate
Description:
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 <= 10^9).
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.
In the example Karlsson must initially break a chocolate into pieces of sizes 3 × 6 and 2 × 6 . After that he can eat all chocolate but the boy's piece that would finally be 1 × 6 . Karlsson cannot, for example, cut a chocolate initially into pieces of sizes 5 × 5 and 1 × 5 --- after doing so, he would have to successively cut a piece away from the first one several times, that would offend the boy.
Examples:
Sample Input
6 5
Sample Output
24
Time Limitation: 1 s
Memory Limitation: 33 MB
Score: 50 Points Language:
网络资源的拷贝粘贴 备份参考之用
Showing posts with label 算法. Show all posts
Showing posts with label 算法. Show all posts
26 March 2007
Subscribe to:
Posts (Atom)
-
{
New Yorker
(11)
}
{
fiction
(11)
}
{
Programming
(9)
}
{
people
(7)
}
{
Google
(6)
}
{
algorithm
(5)
}
{
Internet
(4)
}
{
MIT Media Lab
(4)
}
{
photo
(4)
}
{
picture
(4)
}
{
United States presidential election 2008
(3)
}
{
book
(3)
}
{
冯象
(3)
}
{
电影
(3)
}
{
Erik Demaine
(2)
}
{
Information Retrieval
(2)
}
{
Neil Gaiman
(2)
}
{
Power Law
(2)
}
{
Steve_Jobs
(2)
}
{
movie
(2)
}
{
典故
(2)
}
{
思维的乐趣
(2)
}
{
Art
(1)
}
{
Auto Summarization
(1)
}
{
Barack Hussein Obama
(1)
}
{
Classical Music
(1)
}
{
French
(1)
}
{
Gallery
(1)
}
{
Google Video
(1)
}
{
HARUKI MURAKAMI
(1)
}
{
Hilary Clinton
(1)
}
{
Javascript
(1)
}
{
Psychology
(1)
}
{
cheat sheet
(1)
}
{
data structure
(1)
}
{
foosball
(1)
}
{
lyrics
(1)
}
{
movie making
(1)
}
{
music
(1)
}
{
poem
(1)
}
{
ranking
(1)
}
{
wikipedia
(1)
}
{
三联生活周刊
(1)
}
{
拍电影
(1)
}
{
数学之美系列
(1)
}
{
村上春树
(1)
}
{
算法
(1)
}
{
美术馆
(1)
}