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<map>
using namespace std;
#define MN 100000
#define MOD 1000000007
int p[MN+5],pn,a[MN+5],an;
map<int,int> f;
inline int pw(int x,int y)
{
	int r=1;
	for(;y;y>>=1,x=1LL*x*x%MOD)if(y&1)r=1LL*r*x%MOD;
	return r;
}
int main()
{
	int n,k,i,x,u=0,ans=0;
	scanf("%d%d",&n,&k);
	if(n%2==0)n/=2,u=1;
	for(i=2,x=n;i*i<=x;++i)if(x%i==0)for(p[++pn]=i;x%i==0;)x/=i;
	if(x>1)p[++pn]=x;
	for(i=1;i*i<n;++i)if(n%i==0)a[++an]=i,a[++an]=n/i;if(i*i==n)a[++an]=i;
	sort(a+1,a+an+1);
	for(i=1;i<=an;++i)f[a[i]]=pw(k,u?a[i]:a[i]+1>>1);
	for(x=1;x<=pn;++x)for(i=an;i;--i)if(a[i]%p[x]==0)
		f[a[i]]=(f[a[i]]+MOD-f[a[i]/p[x]])%MOD;
	for(i=1;i<=an;++i)ans=(ans+1LL*f[a[i]]*a[i])%MOD;
	printf("%d",ans);
}