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>
#define mo 1000000007
using namespace std;
int n,m,ans;
map<int,int> mp;
int mi(int a,int x)
{
	int ans=1;
	while (x)
	{
		if (x&1) ans=(long long)ans*a%mo;
		a=(long long)a*a%mo;
		x>>=1;
	}
	return ans;
}
int work(int p)
{
	if (mp.count(p)) return mp[p];
	int ans=0;
	for (int i=1;i*i<=p;i++) if (p%i==0)
	{
		if (i!=p) ans=(ans-work(i))%mo;
		if ((p/i!=i)&&(p/i!=p)) ans=(ans-work(p/i))%mo;
	}
	ans=(ans+mo)%mo;
	if (n/p%2==0) ans=(ans+mi(m,p))%mo;
	else if (p&1) ans=(ans+mi(m,(p+1)/2))%mo;
	else ans=(ans+mi(m,p/2))%mo;
	//if ((n%(2*p)==0)&&(2*p!=n)) ans=(ans+mi[2*p]-mi[p])%mo;
	return mp[p]=ans;
}
int main()
{
	scanf("%d%d",&n,&m);
	//mi[0]=1;for (int i=1;i<=n;i++) mi[i]=(long long)mi[i-1]*m%mo;
	//for (int i=1;i*i<=n;i++) if (n%i==0) {ans+=work(i);ans+=work(n/i);}
	work(n);
	int ans=0;
	for (map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
	{
		//cerr<<it->first<<' '<<it->second<<endl;
		//if ((it->first==n)&&(it->first!=1)) continue;
		ans=(ans+(long long)it->first*it->second)%mo;
	}
	printf("%d\n",ans);
}