#abc179e. [abc179_e]Sequence Sum
[abc179_e]Sequence Sum
Problem Statement
Let us denote by the remainder of the Euclidean division of by .
Let be the sequence that is defined by the initial value and the recurrence relation . Find .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print .
Sample Input 1
6 2 1001
Sample Output 1
1369
The sequence begins Therefore, the answer is .
Sample Input 2
1000 2 16
Sample Output 2
6
The sequence begins Therefore, the answer is .
Sample Input 3
10000000000 10 99959
Sample Output 3
492443256176507