Can this be solved using prime sieve?......The constraints are very large

The constraints are very large

u are not required to use prime sieve,
u just have to deal with creating substring and then converting to a number then creating subsequent substring , so on and so forth…
u are not where dealing with creating a prime sieve