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;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
typedef long long ll;
typedef pair<double,int> P;
const double EPS=1e-10;
const int MOD=1e9+7;
#define EQ(a,b) fabs(a-b)<EPS

ll N,K;

vector<ll> dp;
vector<ll> divisor;

ll mod_pow(ll n,ll m){
	ll ret=1;
	while(m){
		if (m&1){
			ret*=n;
			ret%=MOD;
		}
		n*=n;
		n%=MOD;
		m>>=1;
	}
	return ret;
}

ll mod_inverse(ll n){
	return mod_pow(n,MOD-2);
}

void div(){
	for(ll d=1;d*d<=N;d++){
		if (N%d==0){
			divisor.push_back(d);
			if (N/d!=d){
				divisor.push_back(N/d);
			}
		}
	}
	sort(divisor.begin(),divisor.end());
}

int main(){
	scanf("%lld %lld",&N,&K);
	div();
	dp.resize(divisor.size());
	REP(i,(int)divisor.size()){
		ll d=divisor[i];
		dp[i]=mod_pow(K,(d+1)/2);
		REP(j,i){
			if (d%divisor[j]==0){
				dp[i]=(dp[i]-dp[j]+MOD)%MOD;
			}
		}
	}
	ll ans=0;
	REP(i,(int)divisor.size()){
		ll d=divisor[i];
		if (d%2==1){
			ans+=dp[i]*d%MOD;
		}else{
			ans+=dp[i]*d%MOD*mod_inverse(2)%MOD;
		}
		ans%=MOD;
	}
	printf("%lld\n",ans);
	return 0;
}
