#arc135f. [arc135_f]Delete 1, 4, 7, ...
[arc135_f]Delete 1, 4, 7, ...
Problem Statement
You are given an integer . On an integer sequence , let us do the operation below exactly times.
- Let be the current number of terms in . For all such that and , delete the -th term of , simultaneously.
Find the sum of the terms of after operations, modulo .
Constraints
Input
Input is given from Standard Input from the following format:
Output
Print the sum of the terms of after operations, modulo .
Sample Input 1
10 2
Sample Output 1
25
- Initially, we have .
- After the first operation, we have .
- After the second operation, we have .
- The sum of the terms here is .
Sample Input 2
10 10
Sample Output 2
0
- After the second operation, we have (same as Sample Input 1).
- After the third operation, we have .
- After the fourth operation, we have .
- After the fifth operation, is empty.
- In the sixth and subsequent operations, remains empty, where the sum of the terms is .
Sample Input 3
10000 10
Sample Output 3
862816