Coding puzzles generally ask to give result mod (10^9+7). Refer the explanations here.
Suppose I have a 2 very big number; say 2 large string of numeric characters. I need to add them and result processed as mod (10^9+7). How can i achieve that.
e.g. if they were small numbers code will look like
Integer a = Integer.parseInt("123");
Integer b = Integer.parseInt("456");
Integer result = (a+b)%(10^9+7);
System.out.println("result"+result);
How to do same with very big numbers ?
Integer a = Integer.parseInt("123456474575756568568786786786786783453453");
Integer b = Integer.parseInt("456534543654564567567567567567564564456");
Integer result = (a+b)%(10^9+7);
System.out.println("result"+result);
In this case something other than Integer needs to be used and "add","modulo" operation should be performed.
I could not easily use BidInteger, BigDecimal in this case. Please suggest.