I was just practicing Question in Codechef and I came through this Question:

Question: PRIME1

I was trying my algo to submit this problem but every time I was getting TLE. I thought there must be a better algo than this. So, I went for the solution and this is the result I got.

My Solution: https://www.codechef.com/viewsolution/26858556

Random Solution: https://www.codechef.com/viewsolution/26856596

My Solution got TLE and in later case it got accepted. Please review it.