You have a rectangular sheet of paper of size W×H. Hyunjung needs a sheet whose area is exactly A, so she wants to fold this sheet into a sheet of area A.
Every fold is made along a straight line and must obey two conditions.
- The fold line is parallel to one side of the rectangle.
- After the fold, the width and the height are both still integers.
When a sheet of width w is folded along a vertical line, the width is split into two pieces of lengths x and w−x, and the width after the fold is the longer piece, max(x,w−x). Folding the height works the same way. The folded sheet is a rectangle again, and the side that was not folded keeps its length.
For example, folding a 5×3 sheet at width 4 gives a 4×3 sheet. Folding the same 5×3 sheet at height 1 gives a 5×2 sheet.
Given W, H, and A, decide whether a sheet of area A can be made, and if it can, find the minimum number of folds.