-Made some optimizations and finally got it to be accepted. There are still some optimizations that could be done, maybe i will try them later to see how much faster it runs. For example, the largest factorial could be saved so the search for the largest calculated factorial below N would not have to be done, we could just get this largets factorial and start calculating the factorial of N from it.