I am building up a java program but don't have the right idea on how to resolve its math problem.
The tasks is to cover the wall with wallpaper.
The wall has width $a$ (input) and height $b$ (input). I can use wallpaper with dimensions 1 × 1, 2 × 2 up to $2^n$ × $2^n$ ($n$ is an input). I want to "dress" the wall with wallpapers with the biggest wallpapers available and as few of them as possible.
The output I need is just a number of wallpapers used.
An example: 3 inputs are: $a = 22$, $b = 29$, and $n = 3$.
This means the the wall is 22 × 29 and the max wallpaper is sized $2^3$ × $2^3$ (8 by 8). The wall should then be filled like:

So the output (number of needed wallpapers) would be 53.
Since $a$ and $b$ can be large (up to $10^18$), the best thing would be do NOT use loops (recursive equations) for it. The $n$ can be up to 30.