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 pair<int,int> pii;

const int mo=1e9+7;
const int inv2=5e8+4;
const int maxn=100003;

int qpow(int x,int p){
	int rt=1;
	while(p){
		if(p&1)rt=(1ll*rt*x)%mo;
		x=(1ll*x*x)%mo;
		p>>=1;
	}
	return rt;
}
int fac[maxn],pw[maxn],sz,n,k,res;
int main(){
	scanf("%d%d",&n,&k);
	vector<int> v;
	for(int i=1;1ll*i*i<=n;++i){
		if(n%i==0){
			fac[++sz]=i;
			pw[sz]=qpow(k,i/2+i%2);
			if(1ll*i*i!=n)v.push_back(n/i);
		}
	}
	for(int i=v.size()-1;i>=0;--i){
		int j=v[i];
		fac[++sz]=j;
		pw[sz]=qpow(k,j/2+j%2);
	}
//	for(int i=1;i<=sz;++i)printf("%d %d ^\n",fac[i],pw[i]);
	for(int i=1;i<=sz;++i){
		for(int j=1;fac[j]<fac[i];++j)
			if(fac[i]%fac[j]==0)
				(pw[i]-=pw[j])%=mo;
		int x=1ll*pw[i]*fac[i]%mo;
		if(fac[i]%2==0)x=1ll*inv2*x%mo;
		res=(res+x)%mo;
//		printf("%d %d !\n",fac[i],pw[i]);
	}
	printf("%d\n",(res+mo)%mo);
	return 0;
}

