asked 03 Oct '12, 14:32

The solution uses dynamic programming approach. The MOD operation is simple. Since the answer can be really big, instead of storing the final answer and taking the modulus , you can take the modulus at each step , thus keeping the number within the range. You may find Modular Arithmetic useful. answered 03 Oct '12, 17:03
