//my code for smallfactorial,it's giving correct output in my system but not here..please tell me whats wrong in it???
asked 06 Feb '14, 21:14

it will not work for larger inputs...by larger i mean nos like 2030 will also give a WA...as integer will overflow!!! try putting 100...the worst case!!! answered 06 Feb '14, 21:23

shivali24: Just think about it for a while. What's the range of int? Approximately 10^9. What's the range of long long? Approximately 10^18. How large can the result get? Try a calculator: 30! is around 10^32. Well... shit. Of course it won't work with any integer type of C/C++. Try using "bigint"s  represent a number as an array of base10 digits. (It works a bit faster if you use a larger base.) You just need to implement the addition and multiplication of such numbers, which is easy enough in O(number of digits ^2) in the same way as you'd do it on paper. answered 06 Feb '14, 22:07
