here is the solution
This is what the question asks :
there is a function f which takes m,n,k. m decides how many times the loop runs.
Inside the loop , you check if k divides n , then n=n/k. If it doesnot n=n*k .
Now what will happen ?
ex : let m =100 , n=24 ,k=2 .
so m=1 …
now 2 divides 24 . so 24 becomes 12.
now 2 divides 12 . so 12 becomes 6.
now 2 divides 6 . so 6 becomes 3.
now 2 does not divide 6 so 3 becomes 3*2 =6.
now 2 divides 6 , so 6 becomes 3.
now 2 does not divide 3 so 3 becomes 6…
notice this keep on alternating .
so this is the algo :
- take p =highest power of k that divides n .
- reduce n =n/(k^p) and reduce m=m-p. i am taking reverse loop from m to 1.
- if m gets smallesr than zero in between step 2 , break the loop and print the answer.Exit the algo.
- if not , then n will oscillate from n, nk . and hence if m%2 ==0 then answer will be n else nk.
I have taken getint() , you just take scanf(). That is just for fast input . Ignore getchar_unlocked . The power() used gives me highest power of k that divides n.