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>
using namespace std;
#define ll long long
#define mod 1000000007LL
 
ll h[100010],f[100010],n,k,tot,ans;
 
inline ll rd()
{
    ll x=0;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar());
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x;
}
 
inline ll ksm(ll x,ll y) { ll res=1LL;for (;y;x=x*x%mod,y>>=1) if (y&1) res=res*x%mod;return res; }
 
int main()
{
    n=rd();k=rd();tot=0;
    int sqrtn=(int)sqrt(n);
    for (int i=1;i<=(int)sqrt(n);i++) if (n%i==0) h[++tot]=i;
    if (n==sqrtn*sqrtn)
    {
        for (int i=1;i<tot;i++) h[tot*2-i]=n/h[i];
        tot=tot*2-1;
    }
    else
    {
        for (int i=1;i<=tot;i++) h[tot*2-i+1]=n/h[i];
        tot<<=1;
    }
    f[1]=ans=k;
    for (int i=2;i<=tot;i++)
    {
        f[i]=ksm(k,(ll)((h[i]+1)>>1));
        for (int j=1;j<i;j++) if (h[i]%h[j]==0) f[i]=(f[i]-f[j]+mod)%mod;
        if (h[i]&1) ans=(ans+f[i]*h[i])%mod;
        else ans=(ans+f[i]*(h[i]>>1))%mod;
    }
    printf("%lld\n",ans);
    return 0;
}