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;
typedef vector<ll> vl;
const ll M = 1e9+7;
const int MN = 100100;
vl fac;
unordered_map<ll,ll> dp;
inline ll mul(ll a, ll b) {return (a*b)%M;}
ll bp(ll b, ll p) {
	ll ac = 1;
	while(p) {
		if(p&1) {
			ac = mul(ac,b);
		}
		b = mul(b,b);
		p >>= 1;
	}
	return ac;
}
ll n,k;
ll ds(ll v) {
	if(dp.find(v) != dp.end()) {return dp[v];}
	ll tot = bp(k,(v+1)/2);
	for(int i=0;i<fac.size();i++) {
		if(fac[i] >= v) break;
		if(!(v%fac[i])) {
				tot -= ds(fac[i]);
		}
	}
	tot = ((tot%M)+M)%M;
	return dp[v] = tot;
}
const ll H = 500000004;
int main() {
	scanf("%lld %lld",&n,&k);
	for(int i=1;i*i<=n;i++) {
		if(!(n%i)) {fac.push_back(i);
			if(i != n/i) {
			fac.push_back(n/i);}}
	}
	sort(fac.begin(),fac.end());
	ll res = 0;
	for(int i=0;i<fac.size();i++) {
		if(fac[i]&1) {
			res += ds(fac[i])*fac[i];
		} else {
			res += ((ds(fac[i])*H)%M)*fac[i];
		}
		//printf("oof %d = %lld\n",fac[i],ds(fac[i]));
		res %= M;
	}
	res = ((res%M)+M)%M;
	printf("%lld\n",res);
}