1) what is k doing? Why isnt it just if !n%j print?
2) you only have to go to sqrt n+1 in the inner loop, which will become slow in a hurry.
3) n is useless, just use i.
I am here just to say about efficiency. This is not efficient algorithm. Search google for Sieve of Eratosthenes, which is efficient for finding primes in given interval.