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<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,b,a) for(int i=b;i>=a;i--)
#define mset(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
char ch;
int read(){int n=0,p=1;for(ch=getchar();ch<'0' || '9'<ch;ch=getchar())if(ch=='-') p=-1;for(;'0'<=ch && ch<='9';ch=getchar()) n=n*10+ch-'0';return n*p;}
const int mo=1e9+7,M=1e5+5;
ll n,k,m,num,ans,a[M][2],b[M],f[M];
ll qmi(ll x,ll n)
{
	ll t=1;
	for(;n;n>>=1,x=x*x%mo) if(n&1) t=t*x%mo;
	return t;
}
void dfs(int id=1,int x=1)
{
	if(id>m)
	{
		b[++num]=x;
		return;
	}
	for(int j=0,t=1;j<=a[id][1];j++,t=t*a[id][0]) dfs(id+1,x*t);
}
void pre()
{
	ll t=n;
	for(ll i=2;i*i<=t;++i)
		if(t%i==0)
			for(a[++m][0]=i;t%i==0;t/=i) a[m][1]++;
	if(t>1) a[++m][0]=t,a[m][1]=1;
	dfs();
	sort(b+1,b+num+1);
}
int main()
{
	n=read(),k=read();
	pre();
	fo(i,1,num)
	{
		int x=b[i];
		f[i]=qmi(k,(x+1)/2);
		fo(j,1,i-1)
			if(x%b[j]==0) f[i]=(f[i]-f[j]+mo)%mo;
		ans=(ans+(ll)f[i]*(x&1?x:x/2)%mo)%mo;
	}
	printf("%lld",ans);
	return 0;
}
