Under construction

Still being built. Things may change

Symmetry

Time limit1sMemory limit128 MB

Summary
Count the squares a recursive center-splitting process marks on an N by M grid, where each step splits an odd-by-odd field into four half-sized subfields.
Level

Medium5 of 10

Topics
Recursion, Math, Divide and conquer, Implementation
Solved
No attempts yet

Problem

Farmer John loves symmetry and is arranging his cows on a field partitioned into an N×MN \times M grid (1≤N≤1091 \le N \le 10^9, 1≤M≤1091 \le M \le 10^9).

To preserve symmetry, he places cows as follows. He puts one cow on the exact center square of the field; if the field has no center square, he stops. He then splits the field into four equally sized subfields, separated by the row and column of the center cow, and arranges cows on each subfield in the same way. He repeats this on ever-smaller subfields until a subfield has no center square or can no longer be divided.

A field has a center square only when both of its side lengths are odd. Splitting an N×MN \times M field (with NN and MM both odd) produces four subfields of size N−12×M−12\frac{N-1}{2} \times \frac{M-1}{2}.

For example, if N=7N = 7 and M=15M = 15, Farmer John places a cow at row 4, column 8, then processes each resulting 3×73 \times 7 subfield; in each 3×73 \times 7 subfield he places a cow at row 2, column 4 and processes each resulting 1×31 \times 3 subfield. The process is shown below (C denotes a cow):

...............    ...............    .......|.......    .C.|.C.|.C.|.C.
...............    ...............    ...C...|...C...    ---C---|---C---
...............    ...............    .......|.......    .C.|.C.|.C.|.C.
............... -> .......C....... -> -------C------- -> -------C-------
...............    ...............    .......|.......    .C.|.C.|.C.|.C.
...............    ...............    ...C...|...C...    ---C---|---C---
...............    ...............    .......|.......    .C.|.C.|.C.|.C.

This field needs 21 cows. In contrast, if N=M=5N = M = 5, only one cow is needed, because the resulting 2×22 \times 2 subfields have no center square. Help Farmer John determine how many cows he needs.

Input

A single line with two space-separated integers NN and MM.

Output

The number of cows needed, on a single line.

Examples2

  1. Example 1

    Input
    7 15
    
    Expected output
    21
    
  2. Example 2

    Input
    5 5
    
    Expected output
    1