I am unable to understand why this solution doesn’t pass the two remaining test cases. I referred to the Editorial for the solution, and my solution is supposed to work exactly the way the Editorial suggests to. Please help!
You can see the modified code here. It was because of overflow issues. Variable “num” overflows in your code. Take for example, a prime just less than 10^7, in that case, num = p*p*p, which overflows. Just modified your formula a bit. Have a look at the solution and if you have any doubts, ask below in comments.
If you feel your question was answered, mark it as accepted.
Nicely answered. Thanks!