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 int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}

int N,K;

signed main(){
    cin>>N>>K;

    vint ei;
    for(int i=1;i*i<=N;i++){
        if(N%i)continue;
        ei.pb(i);
        if(i*i!=N)ei.pb(N/i);
    }

    sort(all(ei));
    vint dp(ei.size());
    int ans=0;
    for(int i=0;i<ei.size();i++){
        dp[i]=mpow(K,(ei[i]+1)/2);
        for(int j=0;j<i;j++)if(ei[i]%ei[j]==0)dp[i]=(dp[i]-dp[j]+mod)%mod;
        if(ei[i]%2)ans=(ans+dp[i]*ei[i])%mod;
        else ans=(ans+dp[i]*ei[i]/2)%mod;
    }
    cout<<ans<<endl;
    return 0;
}
