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;
const int mod=1e9+7;
map<int,int> f;
vector<int> hve;
int ans=0,n,k;
int qpower(int a,int c){
	int re=1;
	while (c){
		if (c&1) re=1ll*re*a%mod;
		c>>=1;a=1ll*a*a%mod;
	}
	return re;
}
int solveit(int v){
	if (f.find(v)!=f.end()) return f[v];
	int re=qpower(k,(v+1)/2);
	for (int i=1;i*i<=v;i++){
		if (v%i==0 && i!=v){
			re=(re-solveit(i)+mod)%mod;
			if (i!=1 && i*i!=v) re=(re-solveit(v/i)+mod)%mod;
		}
	}
	f[v]=re;
	return re;
}
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i*i<=n;i++){
		if (n%i==0){
			hve.push_back(i);
			if (i*i!=n) hve.push_back(n/i);
		}
	}
	sort(hve.begin(),hve.end());
	for (int i=0;i<hve.size();i++){
		int ff=solveit(hve[i]);
		ans=(ans+1ll*ff*((hve[i]&1)?hve[i]:hve[i]/2)%mod)%mod;
	}
	printf("%d\n",ans);
	return 0;
} 