Why am I getting 10% wrong answer on this question?

Question : https://www.urionlinejudge.com.br/judge/en/problems/view/1168
My solution : http://ideone.com/RW5deD
Gives correct answer on 90% cases. I don’t find any corner cases here.
Where am I going wrong?

Bump.Anybody?

why donot you use string in place of biginteger .

But Biginteger never fails either,I’m just curious why is there this 10% fallacy in the code,but yeah I can consider using string too.