Back to General discussions forum
Hi, I have a problem with #14 Modular Calculator, the input in the test data is so big that even unsigned long int is not enough to hold it all and eventually the number gets corrupted, I tested my code with every normal end values and it works, only on the test data with those huge values it fails, I even tried using the windows calculator and it failed because the number gets so big.
I would've used a different data type such as float which is bigger but then it's impossible to use modulo on it (has to be an int)
So please what can I do about it?
Hi! Welcome to the forum!
In similar cases you can try typing problem title or number in the "search" box above :) You will find several topics about it, like this one.
The main idea is that you may avoid large intermediate results if you slightly rewrite your calculations keeping in mind main principles of modular arithmetics.
(though of course you also can implement long-arithmetic manually)
Feel free to ask more if these links will not provide enough help!
Hai tazdingo. what language do you use? if you use Java, try google for the data type called BigInteger
This problem can be solved easily without using BigInteger and you'll also learn much more if you don't use BigInteger