if N is a multiple of K,
divide N by K
else,
multiply N by K

print N

Perform the operation F on N.

QUICK EXPLANATION:

The given pseudo code’s complexity will be O(M) and 1<=M<=10^10
Hence, directly implementing the pseudo code will result in TLE.

EXPLANATION:

If N is not divisible by K, then the answer for the problem will be either N or KN.
If M is odd, then the answer will be KN, else it will be N
If N is divisible by K, then we go on dividing N by K until it is no more divisible by K, once the value of N is not divisible by K, we can easily find out the answer. As, the answer now can be either N or N*K.

Note that while dividing N by K, it should not be divided more than M times.

The pseudo code will be:

if K == 1:
answer = N
else:
while N%K==0 and m!=0:
N = N/K
M = M-1
if M%2==1:
N*=K
answer = N

@karankapoor you have to divide n by k till you dont get it is divisible…but in any case you are diving only by once! so correct that and read editorial once you will get it