# Getting TLE

https://codeforces.com/contest/1350/problem/A
my solution
https://codeforces.com/contest/1350/submission/80846979
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).

;;

ya nice approach

what is flagged?