Two cases have runtime error help me out

since n can be as large as 2,147,483,647 and when you are declaring ll int a[n+1]={0}; it generates run time error as we can’t make an array of the size as of the order 10^9.also your code complexity is o(n) so even if you could be saved using dynammic allocation you will eventually get TLE , because your idea of finding factors can be optimized further
refer this :-


and modify your code such that you can find all the factors in atleast o(sqrt(n))

you can refer to my code :-

In case of any doubt feel free to ask :slight_smile:
mark your doubt as RESOLVED if you got the answer

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.