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 <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

const int P=1000000007;

vector<int> f,d;
int n,K,ans;

inline int quick_power(int x,int y)
{
	int ret=1;
	for (;y;y>>=1,x=1ll*x*x%P) if (y&1) ret=1ll*ret*x%P;
	return ret;
}

void generate_state()
{
	for (int x=1;x*x<=n;++x)
		if (!(n%x))
		{
			d.push_back(x);
			if (x*x!=n) d.push_back(n/x);
		}
	sort(d.begin(),d.end()),f.reserve(d.size());
}

inline void update(int &x,int y){(x+=y)%=P;}

void dp()
{
	for (int i=0;i<(int)d.size();++i)
	{
		f[i]=quick_power(K,d[i]+1>>1);
		for (int j=0;j<i;++j) if (!(d[i]%d[j])) update(f[i],P-f[j]);
		if (d[i]&1) update(ans,1ll*f[i]*d[i]%P);
		else update(ans,1ll*f[i]*(d[i]>>1)%P);
	}
}

int main()
{
	//freopen("rotpal.in","r",stdin),freopen("rotpal.out","w",stdout);
	scanf("%d%d",&n,&K),generate_state(),dp(),printf("%d\n",ans);
	//fclose(stdin),fclose(stdout);
	return 0;
}