Code not passing any testcase bu is running properly with example given in question.
code…
Prateek Loves Candy
You are required to use prime seive optimisation in your code. Refer to the video given under number theory section on the same and then try to implement that logic only…