eolymp
bolt
Try our new interface for solving problems
Problems

Symmetry

Symmetry

Farmer John loves symmetry and is currently arranging his cows on his field partitioned into an $n \cdot m$ grid. To preserve symmetry, Farmer John places cows in the following way. He puts a cow in the very center grid-square of the field; if no such grid-square exists, he simply stops. Then he partitions the field into four equal-sized smaller fields (separated by the row and column of the cow in the center) and arranges cows on each of those fields as before. He repeats the partitioning for ever-smaller fields until no center grid-square of a field exists or the field cannot be subdivided. By way of example, if $n = 7$ and $m = 15$ then Farmer John will place a cow in row $4$, column $8$ and arrange each of the resulting $3 \cdot 7$ fields. In each of the $3 \cdot 7$ fields, Farmer John will place a cow in row $2$, column $4$ and arrange each of the resulting $1 \cdot 3$ fields. The process is shown here (where $C$ denotes a cow): \includegraphics{https://static.e-olymp.com/content/98/986f7a3140b4891ca1e7d23d94f09a2128ee46b9.jpg} $21$ cows are required for this field. On the other hand, if $n = m = 5$ then Farmer John will only need to place one cow since the resulting $2 \cdot 2$ fields do not have center grid-squares. Help Farmer John determine how many cows he needs to arrange his field. \InputFile Two integers $n$ and $m~(1 \le n \le 10^9, 1 \le m \le 10^9)$. \OutputFile Print the number of cows needed.
Time limit 1 second
Memory limit 128 MiB
Input example #1
7 15
Output example #1
21
Source 2011 USACO Bronze Division, January