I am getting a Wrong answer , I am unable to detect whats wrong , Please help !
Link to my solution : https://www.codechef.com/viewsolution/21663313
Link to the very simple problem : https://www.codechef.com/problems/FCTRL2/
I am getting a Wrong answer , I am unable to detect whats wrong , Please help !
Link to my solution : https://www.codechef.com/viewsolution/21663313
Link to the very simple problem : https://www.codechef.com/problems/FCTRL2/
As you know factorials grow very fast and integers can store values only upto a certain range so you can see your program would result in overflows.You can try your ans on for ex 25.Your code will produce 2076180480 which is incorrect.Hence WA.
PS:you can write a string multiplication code in c++ or can use BigInteger class of Java if u want.
Happy Coding!!
Okay , Thanks !
Whoever called 100! a “small factorial” must have been joking.
For this particular question, switch to python which has in built support for large numbers
The solution you have written would work correctly if there was no range for data types in c++. But data types come with their ranges and for saving the value of 100! which has 154 digits in its decimal form can’t be saved in any data type available in c++.
To counter this problem you can do a number of things like:
Another thing you may do is to use a vector and as save the value of the multiplication in each term as long as the value of that element doesn’t cause overflow.
I suppose I have provided you with a basic idea to use to solve this question.
I wish I could hit that UpVote button (Sadly I dont have enough rep. pts)
Thanks Though !
Try the concept of unbounded integers, which you can implement using array.
You can accept his answer… he will get 15 reputation…
Just click on tick button @prembharwani
And giving answer to your question… As rightly said by everyone else you need string multiplication and stuff…
But with python , simple code will work… as it takes care of big integers (which can’t be stored in simple data types) on its own…