#arc064d. [arc064_d]Rotated Palindromes
[arc064_d]Rotated Palindromes
Problem Statement
Takahashi and Aoki are going to together construct a sequence of integers.
First, Takahashi will provide a sequence of integers , satisfying all of the following conditions:
- The length of is .
- Each element in is an integer between and , inclusive.
- is a palindrome, that is, reversing the order of elements in will result in the same sequence as the original.
Then, Aoki will perform the following operation an arbitrary number of times:
- Move the first element in to the end of .
How many sequences can be obtained after this procedure, modulo ?
Constraints
Input
The input is given from Standard Input in the following format:
Output
Print the number of the sequences that can be obtained after the procedure, modulo .
Sample Input 1
4 2
Sample Output 1
6
The following six sequences can be obtained:
Sample Input 2
1 10
Sample Output 2
10
Sample Input 3
6 3
Sample Output 3
75
Sample Input 4
1000000000 1000000000
Sample Output 4
875699961