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>
using namespace std;
typedef long long LL;
const int mod = (int)1e9 + 7;
int n, m;
map<int, int> Hash;
int mod_pow(int x, int k) {
	int ret = 1;
	for( ; k > 0; k >>= 1, x = (LL)x * x % mod)
		(k & 1) && (ret = (LL)ret * x % mod);
	return ret;
}
int F(int x) {
	if(Hash.count(x))
		return Hash[x];
	int ret = mod_pow(m, (x + 1) >> 1);
	x > 1 && (ret -= F(1)) < 0 && (ret += mod);
	for(int i = 2; i * i <= x; ++i) {
		if(x % i > 0)
			continue;
		(ret -= F(i)) < 0 && (ret += mod);
		i * i < x && (ret -= F(x / i)) < 0 && (ret += mod);
	}
	return Hash[x] = ret;
}
int main() {
	scanf("%d%d", &n, &m);
	int ans = 0;
	for(int i = 1; i * i <= n; ++i) {
		if(n % i > 0)
			continue;
		ans = (ans + (LL)F(i) * (i >> !(i & 1))) % mod;
		if(i * i < n)
			ans = (ans + (LL)F(n / i) * ((n / i) >> !((n / i) & 1))) % mod;
	}
	printf("%d\n", ans);
	return 0;
}