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 <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

typedef long long s64;

const int MaxNF = 1344;

const int M = 1000000007;
const int I2 = M + 1 >> 1;

inline int modpow(int a, const int &n)
{
	int res = 1;
	for (int i = n; i; i >>= 1)
	{
		if (i & 1)
			res = (s64)res * a % M;
		a = (s64)a * a % M;
	}
	return res;
}

int n, nK;

int nF = 0, fac[MaxNF];

int f[MaxNF];

int main()
{
	cin >> n >> nK;

	int l = floor(sqrt(n));
	for (int i = 1; i <= l; ++i)
		if (n % i == 0)
		{
			fac[nF++] = i;
			if (i != n / i)
				fac[nF++] = n / i;
		}

	sort(fac, fac + nF);

	int res = 0;
	for (int i = 0; i < nF; ++i)
	{
		f[i] = modpow(nK, fac[i] + 1 >> 1);

		for (int k = 0; k < i; ++k)
			if (fac[i] % fac[k] == 0)
				f[i] = (f[i] + M - f[k]) % M;

		int ways = (s64)f[i] * fac[i] % M;
		if (~fac[i] & 1)
			ways = (s64)ways * I2 % M;

		res = (res + ways) % M;
	}

	cout << res << endl;

	return 0;
}