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<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mk(a,b) make_pair(a,b)

typedef long long ll;
typedef pair<ll,ll> pll;

ll N,K;
vector<pll> V;
vector<ll> R;
ll mod = 1000000007;
ll ans = 0;

ll pow_mod(ll a,ll b)
{
    if(b == 0)return 1;
    ll res = pow_mod(a * a % mod,b / 2);
    if(b & 1)res = res * a % mod;
    return res;
}

ll unit(ll n)
{
    ll num = pow_mod(K,(n + 1) / 2);

    for(int i = 0; i < V.size(); i++)
        if(n % V[i].fi == 0)num = (num - V[i].se + mod) % mod;
    V.push_back(mk(n,num));

    if(n % 2 == 0)return (num * (n / 2)) % mod;
    return num * n % mod;
}

int main()
{
    scanf("%lld%lld",&N,&K);

    for(ll i = 1; i <= (ll)sqrt(N); i++)
    {
        if(N % i == 0)
        {
            R.push_back(i);
            if(i * i != N)R.push_back(N / i);
        }
    }

    sort(R.begin(),R.end());

    for(int i = 0; i < R.size(); i++)ans = (ans + unit(R[i])) % mod;
    printf("%lld\n",ans);
    return 0;
}
