Given a large N, I need to iterate through all phi(k) such that 1 < k < N :
O(N logN)
I think you can go the other way around. Instead of factorizing an integer k to get phi(k), you can attempt to generate all integers from 1 to N from primes and get phi(k) quickly. For example, if Pn is the maximum prime that is less than N, you can generate all integers less than N by
P1 i 1 * P2 i 2 * ... * Pn i n where each ij run from 0 to [log (N) / log (Pj)] ([] is the floor function).
That way, you can get phi(k) quickly wihout expensive prime factorization and still iterate through all k between 1 and N (not in order but I think you don't care about order).