Accepted on SPOJ
MARBLES - Not able to pass test cases
You are code has a problem of overflow, use big integer class in java then code it.
The cases on spoj are weak
The answer is larger than 7 * 10^18. So for cases much larger than 64 30 the result will be much larger than this which will not fit in the normal range of long long int. That’s why you’re suggested to use BigInteger and i also mentioned that C++ student will face difficulty in handling this long cases because there is nothing like BigInteger in C++, you have to do this using normal arrays. Just read the constraints limit on spoj and hackerblocks as well and just try to calculate for some testcase that how big result You are getting and if it will fit in the long long int range.
i won’t be able to implement division using normal arrays and boost isn’t working on CB IDE
@sanyamaggarwal, implementing it in array representation can be little tricky.
However you can use strings and perform division as
string division(string number, int divisor)
{
string ans;
int idx = 0;
int temp = number[idx] - '0';
while (temp < divisor)
temp = temp * 10 + (number[++idx] - '0');
while (number.size() > idx)
{
ans += (temp / divisor) + '0';
temp = (temp % divisor) * 10 + number[++idx] - '0';
}
if (ans.length() == 0)
return "0";
return ans;
}
You can use similar approach using arrays and maintaining a pointer where to point.