Here is the problem quote:

“Generate numbers from 1 to N such that each number has only 3 factors and the sum of these consecutive numbers is prime”

for eg:-

N=4, numbers are 1 , 4 , 9 (output)

and 1+4=5 (prime), 4+9=13 (prime)

I tried to solve the problem but takes more time with larger number (10^9), So anyone one can provide me with a more powerful logic to solve this for larger N.