Getting TLE error can it be sorted in python. Want help in optimising code

Hi @shivammishra2408

The approach you have used is a brute-force one. Try to search for more optimized algorithms.
(e.g. Whether a number is prime or not can be checked in O(sqrt(n)) time complexity).

Also study about Sieve of Erastosthenes and Segmented Sieve. These algorithms are optimized for the problem of searching prime numbers less than a given ā€˜n’.

Let me know if you face any problem!