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;
typedef long long LL;
typedef pair <int,int> pii;

const int mod=1e9+7;
inline int add(int x,int y) {return (x+y>=mod) ? (x+y-mod) : (x+y);}
inline int dec(int x,int y) {return (x-y<0) ? (x-y+mod) : (x-y);}
inline int mul(int x,int y) {return (long long)x*y%mod;}
inline int power(int a,int b,int rs=1) {for(;b;b>>=1,a=mul(a,a)) if(b&1) rs=mul(rs,a); return rs;}

const int N=1e5+50;
int n,k;
#define div divc
vector <int> div;
int g[N];
int main() {
	cin>>n>>k; k%=mod;
	div.push_back(1);
	int t=n;
	for(int i=2;i*i<=t;i++) {
		if(!(t%i)) {
			int c=0;
			while(!(t%i)) t/=i, ++c;
			for(int j=div.size()-1;~j;j--) 
				for(int x=i,z=1;z<=c;x*=i,++z) 
					div.push_back(div[j]*x);
		}
	}
	if(t!=1) 
		for(int j=div.size()-1;~j;j--) div.push_back(div[j]*t);
	sort(div.begin(),div.end());
	for(int i=0;i<div.size();i++) 
		g[i]=power(k,(div[i]+1)/2);
	for(int i=0;i<div.size();i++) 
		for(int j=i-1;~j;j--) if(!(div[i]%div[j]))
			g[i]=dec(g[i],g[j]);
	int ans=0;
	for(int i=0;i<div.size();i++)
		ans=add(ans,mul((div[i]&1) ? div[i] : (div[i]/2),g[i]));
	cout<<ans<<'\n';
}