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<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 100005
#define M 200005
#define seed 23333

#define Mo 1000000007

using namespace std;
int i,j,m,n,p,k,F[N],Q[N],ans;
const int inv2=500000004;
void jian(int &x,int y)
{
		x-=y; if (x<0) x+=Mo;
}
void jia(int &x,int y)
{
		x+=y; if (x>=Mo) x-=Mo;
}
int power(int x,int y)
{
		int sum=1;
		for (;y;y>>=1)
		{
				if (y&1) sum=1ll*sum*x%Mo;
				x=1ll*x*x%Mo;
		}
		return sum;
}
int main()
{	
	scanf("%d%d",&n,&k);
	for (i=1;i*i<=n;++i) if (n%i==0)
	{
			Q[++Q[0]]=i;
			if (i*i!=n) Q[++Q[0]]=n/i;
	}
	sort(Q+1,Q+Q[0]+1);
	for (i=1;i<=Q[0];++i)
	{
			F[i]=power(k,(Q[i]+1)/2);
			for (j=1;j<i;++j) if (Q[i]%Q[j]==0) jian(F[i],F[j]); 
	}
	for (i=1;i<=Q[0];++i)
	{
			if (n&1||Q[i]%2==1)	jia(ans,1ll*F[i]*Q[i]%Mo);
			else jia(ans,1ll*F[i]*inv2%Mo*Q[i]%Mo);	 
	}
	printf("%d\n",ans);
}
