Getting TLE

my solution

help me get optimised solution

Obviously, you can not loop it K times as you did because K can be 10e9 and it will result in time limit exceed.
According to problem we need to find smallest possible divisor of N as part of answer.
But for any even N, smallest possible divisor which is f(N) will always be 2 (No need to calculate!)
so every K time 2 will be added in N (N keeps becoming even only!)
so answer when N is even will always be N+2K where 2 is f(N)
now when N is odd:
f(N) will be odd because no even can divide odd and after adding that first f(N) (which is odd) into N (Which is also odd) result will be even and then all fellow f(N) will be 2 again
so answer when N is odd will be N+f(N)+2
(K-1) where f(N) is smallest possible divisor for given N (Without change) and the same can be calculated in N time (maximum).

;;

Implementation of above answer

ya nice approach

what is flagged?

sorry for late reply.
for N is odd can i use ((2n)+(2(k-1)));
since f(n) is same as n.

for n=9,f(n) will be 3 not 9
hence f(n)!=n

yeah i just now found out.
Thanks