An unsigned long long is 64 bits? The maximum factorial you can get in that is 20! If your unsigned long long is 128 bits then the maximum you can get in that is 34! [edit] If you are using floating point numbers you already have only approximations to the correct number after 18!
IMHO factorials should be stored in a lookup table such that result = fact[input]; this is how to optimize factorials for normal use cases. dealing with very large values aside (you have to pick your solution here), there is a *very* accurate factorial approximation function that you can ...
Visual Presentation: Sample Solution: C++ Code : #include<iostream>// Including input-output stream header fileusing namespace std;// Using the standard namespace// Function to calculate factorial recursivelylonglongfactorial(intnum){if(num==0){// If the number is 0return1;// Return 1 becaus...
0215-Kth-Largest-Element-in-an-Array 0216-Combination-Sum-III 0217 Contains Duplicate 0218-The-Skyline-Problem 0219-Contains-Duplicate-II 0220-Contains-Duplicate-III 0221-Maximal-Square 0222-Count-Complete-Tree-Nodes 0224-Basic-Calculator 0225-Implement-Stack-using-Queues 0226-I...