200643: [AtCoder]ARC064 F - Rotated Palindromes

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $1000$ points

Problem Statement

Takahashi and Aoki are going to together construct a sequence of integers.

First, Takahashi will provide a sequence of integers $a$, satisfying all of the following conditions:

  • The length of $a$ is $N$.
  • Each element in $a$ is an integer between $1$ and $K$, inclusive.
  • $a$ is a palindrome, that is, reversing the order of elements in $a$ 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 $a$ to the end of $a$.

How many sequences $a$ can be obtained after this procedure, modulo $10^9+7$?

Constraints

  • $1≤N≤10^9$
  • $1≤K≤10^9$

Input

The input is given from Standard Input in the following format:

$N$ $K$

Output

Print the number of the sequences $a$ that can be obtained after the procedure, modulo $10^9+7$.


Sample Input 1

4 2

Sample Output 1

6

The following six sequences can be obtained:

  • $(1, 1, 1, 1)$
  • $(1, 1, 2, 2)$
  • $(1, 2, 2, 1)$
  • $(2, 2, 1, 1)$
  • $(2, 1, 1, 2)$
  • $(2, 2, 2, 2)$

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

Input

题意翻译

高桥和青木想要一起造一个数列。 首先,高桥会造出一个满足以下条件的数列$a$: * $a$的长度为$N$。 * $a$中的所有元素都是一个$[1,K]$内的整数。 * $a$是一个回文串。 然后,青木会进行任意多次以下的操作: * 把$a$中的第一个元素移到最后。 经过这些步骤,一共可以得到多少种不同的数列$a$呢?答案对1e9+7取模。

加入题单

上一题 下一题 算法标签: