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 For(i, j, k) for(int i = j; i <= k; i++)

using namespace std;

const int Mod = 1e9 + 7;

int Pow(int x, int e){
	int ret = 1;
	while(e){
		if(e & 1) ret = 1ll * ret * x % Mod;
		x = 1ll * x * x % Mod;
		e >>= 1;
	}
	return ret;
}

int n, k, ans;

map<int, int> M;

void calc(int l){
	int ret = Pow(k, (l + 1) / 2);
	for(int i = 1; i * i <= l; ++i)
		if(l % i == 0){
			ret = (ret + Mod - M[i]) % Mod;
			if(i * i != l && i != 1) ret = (ret + Mod - M[l / i]) % Mod;
		}
	int re = l;
	M[re] = ret;
	if(re % 2 == 0) ret = 1ll * ret * Pow(2, Mod - 2) % Mod;
	ans = (ans + 1ll * ret * l) % Mod;
}

int main(){
	scanf("%d%d", &n, &k);
	int i = 1;
	for(; i * i <= n; ++i)
		if(n % i == 0) calc(i);
	for(--i; i; --i)
		if(n % i == 0 && i * i != n) calc(n / i);
	printf("%d\n", ans);
	return 0;
}