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<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int mod=1e9+7;
int n,k,tot,ans;
map<int,int>mp;
int f[100008],dor[100008];

int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*f;
}

int power(int a,int k)
{
    int sum=1;
    for (;k;k>>=1,a=1ll*a*a%mod)
	if (k&1)
	    sum=1ll*sum*a%mod;
    return sum;
}

int main()
{
    n=read(),k=read();
    for (int i=1;1ll*i*i<=n;i++)
	if (n%i==0)
	    {
	        dor[++tot]=i;
		if (n/i!=i) dor[++tot]=n/i;
	    }
    sort(dor+1,dor+tot+1);
    for (int i=1;i<=tot;i++) mp[dor[i]]=i;
    ans=f[1]=k;
    for (int i=2;i<=tot;i++)
	{
	    if ((n/dor[i])&1) f[i]=(power(k,(dor[i]+1)/2)-f[1])%mod;
	    else f[i]=(power(k,dor[i])-f[1])%mod;
	    for (int j=2;1ll*j*j<=dor[i];j++)
		if (dor[i]%j==0)
		    {
			f[i]=(f[i]-f[mp[j]])%mod;
			if (dor[i]/j!=j) f[i]=(f[i]-f[mp[dor[i]/j]])%mod;
		    }
	    ans=(ans+1ll*f[i]*dor[i]%mod)%mod;
	}
    ans=(ans+mod)%mod;
    printf("%d\n",ans);
    return 0;
}
    
    
