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 <cstdio>
#include <algorithm>
#include <map>
using namespace std;

const int mod = 1e9 + 7;

typedef pair<int, int> pii;

int n, K;

int pr(int a, int z) {
	int s = 1;
	while (z > 0) {
		if (z % 2 == 1) s = 1ll * s * a % mod;
		a = 1ll * a * a % mod;
		z /= 2;
	}
	return s;
}

map<int, int> sum;
pii li[200];
int len;

#define fi first
#define se second

int main() {
	//freopen("64D.in", "r", stdin);
	scanf("%d%d", &n, &K);
	int _n = n;
	for (int i = 2; i * i <= _n; ++i) if (_n % i == 0) {
		int c = 0;
		while (_n % i == 0) _n /= i, ++c;
		li[++len] = pii(i, c);
	}

	if (_n != 1) li[++len] = pii(_n, 1);

	for (int d = 1; d * d <= n; ++d) {
		if (n % d == 0) {
			sum[d] = d;
			sum[n / d] = n / d;
		}
	}



	for (int i = 1; i <= len; ++i) {
		for (auto it = sum.begin(); it != sum.end(); ++it) if (it->fi % li[i].fi == 0 && sum.find(it->fi / li[i].fi) != sum.end()) {
			sum[it->fi / li[i].fi] -= sum[it->fi];
		}
	}


	int ans = 0;

	for (pii p : sum) {
		ans = (ans + 1ll * pr(K, (n / p.fi % 2 == 1) ? (p.fi + 1) / 2 : p.fi) * p.se % mod + mod) % mod;
	}

	printf("%d\n", ans);
	return 0;
}
