So i`ve been asked to code an algorithm that decomposes an integer into the product of a base two exponencial and some integer.Something like number = k.(2^n) , k and n being random integers with k restricted to being odd.
My question is not about the programming aspect of this problem but rather the algebraic one as i have failed to came up with a standard procedure into finding one.The problem says thats the combination k.(2^n) is unique for every integer, so i`ve managed to find the combinations for certian numbers but it gets exponencially dificult as the number increases.
For example, given the number 12 the only possible combination under this restrictions is 12 = 3(2^2)
Please feel free to edit and improve anything you feel necessary as english is not my mother language
Start with $M$. If $M$ is odd you are done.
If $M$ is even, let $M_1 =\frac M{2}$ and you have $2^1*M_1$.
If $M_1$ is odd you are done. Otherwise let $M_2 = \frac {M_1}{2}$ and you have $2^2*M_2$.
Repeat. Each step you will have $2^j*M_j$ and so long as $M_j$ is even you will continue to $M_{j+1} = \frac {M_j}2$ and have $2^{j+1}M_{j+1}$.
Eventually this will end you reach an odd $M_k$ and have $2^kM_k$.