Prime visits problem TLE

TLE error in one test case. PLease tell me why?

https://ide.codingblocks.com/#/s/21331

Problem: https://hack.codingblocks.com/practice/p/387/63

Instead of checking everytime whether a no. is prime or not you can take an array an initially store all prime nos. till 1000000 and then call the array and count the prime nos. btw that range

https://ide.codingblocks.com/s/43165
But it still shows TLE error