I believe this has to do with the size of the factorial. If you look at some successful submissions for the problem in C++, you’ll see that they include an extra header which gives them a variable type that allows them to handle such large numbers.
For a lot of problems, you can look at previous submissions. You’ll see them ranked by popularity or you can manually go through a few. A lot of these are well explained by the coders. That’s probably a good first way to start if you are stuck, since responses here will probably be slow.