AtCoder Regular Contest 064
F
Rotated Palindromes
AtCoder
⌀ 2949
原题
← E→
翻译中…

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$.

翻译中…

样例

Input #1
4 2
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)$
Input #2
1 10
Output #2
10
Input #3
6 3
Output #3
75
Input #4
1000000000 1000000000
Output #4
875699961
题目信息
题号
arc064_d
时间限制
2 s
内存限制
256 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。