Ok, I found a testcase where your code produces wrong results. You can do the same
JULKA is a problem where you can easily test your code with a systematic approach. All the big integer stuff is needed for longer inputs only. You can easily generate test cases up to 6 digits and check the result of your code using simple (normal) integer calculations. You can even do it all in your existing program, just separate the output from the calculation, write two for loops, call your calculation and check the result.
This approach was helpful in 95% of all JULKA questions here. The errors typically do not only appear for large input data...