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<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 60; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; }
		p %= m; q *= q; q %= m;
	}
	return p;
}
long long N, K, M[1500], mod = 1000000007; vector<long long>E;
int main() {
	cin >> N >> K;
	for (int i = 1; i*i <= N; i++) {
		if (N%i != 0)continue;
		E.push_back(i);
		E.push_back(N / i);
	}
	sort(E.begin(), E.end());
	E.erase(unique(E.begin(), E.end()), E.end());
	for (int i = 0; i < E.size(); i++) {
		long long cnt = modpow(K, (E[i] + 1) / 2, mod);
		for (int j = 0; j < i; j++) {
			if (E[i] % E[j] == 0)cnt -= M[j]; cnt += mod; cnt %= mod;
		}
		M[i] = cnt;
	}
	long long ret = 0;
	for (int i = 0; i < E.size(); i++) {
		long long G = E[i]; if (G % 2 == 0)G /= 2;
		ret += G*M[i]; ret %= mod;
	}
	cout << ret << endl;
	return 0;
}