This is my solution.
I tried on my own and came across this solution on geeks for geeks.
I did dry it and it worked but the last test case shows an exclamation mark with the test case.
The error displayed in run time error but 5 test case pass while last one doesn’t pass
One test case fails
Increase MAX to 10^4. 500! has much more digits than 500