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> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
const int mo=1e9+7;
int i,j,n,k,f[2005],fac[2005],cnt,ans;
int qs(int x,int y){
	int s=1;
	for(;y;y>>=1,x=(ll)x*x%mo) if (y&1) s=(ll)s*x%mo;
	return s;
}
int main(){
	scanf("%d%d",&n,&k);
	fo(i,1,n){
		if (i*i>n) break;
		if (n%i==0){
			fac[++cnt]=i,fac[++cnt]=n/i;
			if (fac[cnt]==fac[cnt-1]) cnt--;
		}
	}
	sort(fac+1,fac+1+cnt);
	fo(i,1,cnt){
		f[i]=qs(k,(fac[i]+1)>>1);
		fo(j,1,i-1) if (fac[i]%fac[j]==0) (f[i]-=f[j])%=mo;
	}
	fo(i,1,cnt) {
		if (!(fac[i]&1)) fac[i]>>=1;
		(ans+=(ll)f[i]*fac[i]%mo)%=mo;
	}
	printf("%d\n",(ans+mo)%mo);
}