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.

Examples

Input

4 2


Output

6


Input

1 10


Output

10


Input

6 3


Output

75


Input

1000000000 1000000000


Output

875699961
#include <bits/stdc++.h>

const int mod = 1000000007;
typedef long long LL;
void reduce(int & x) { x += x >> 31 & mod; }
int mul(int a, int b) { return (LL) a * b % mod; }
int pow(int a, int b, int res = 1) {
	for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a);
	return res;
}
const int MAXN = 100010;
int n, K, li[MAXN], bak, f[MAXN];
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> K;
	for (int i = 1; i * i <= n; ++i)
		if (n % i == 0) {
			li[++bak] = i;
			if (i * i != n) li[++bak] = n / i;
		}
	std::sort(li + 1, li + 1 + bak);
	int ans = 0;
	for (int i = bak; i; --i) {
		f[i] = pow(K, n / li[i] + 1 >> 1);
		for (int j = i + 1; j <= bak; ++j)
			if (li[j] % li[i] == 0)
				reduce(f[i] -= f[j]);
		int r = n / li[i];
		reduce(ans += mul(f[i], r & 1 ? r : r >> 1) - mod);
	}
	std::cout << ans << std::endl;
	return 0;
}
