if the no range is 10^12 then to cal the prime factor
About prime factorisation
For range upto 10^6, you can directly do.
For range above that, use segmented sieve.
PS: You always need primes upto sqrt(N) ie sqrt(10^12) = 10^6 which is easily achievable.