understanding the problem


can anyone explain in detail what is required in the following program?


My code http://www.codechef.com/viewsolution/3908975

have I misunderstood the question how bad is my code :frowning: need help to improve myself but am having a hard time understanding the problem/Question itself please do lend a helping hand!

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.

m=2 …

now 2 divides 12 . so 12 becomes 6.

m=3 …
now 2 divides 6 . so 6 becomes 3.


now 2 does not divide 6 so 3 becomes 3*2 =6.

m=5 …
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 :

  1. take p =highest power of k that divides n .
  2. reduce n =n/(k^p) and reduce m=m-p. i am taking reverse loop from m to 1.
  3. if m gets smallesr than zero in between step 2 , break the loop and print the answer.Exit the algo.
  4. 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.