
CodePudding user response:
Code to the#include
using namespace std;
Unsigned long long quickpow (unsigned long long, unsigned long long);
Int main ()
{
Ios: : sync_with_stdio (false);
Unsigned long long n, k;
Cin> N> k;//k colors, and n number of ring
Int sum;
If (n==2 | | k==1) sum=0;
Else if ((n& 1)==0) sum=(quickpow (k - 1, n - 1) - (k - 1)) % 1000000007;
The else sum=(quickpow (k - 1, n - 1) + (k - 1)) % 1000000007;
cout
}
Unsigned long long quickpow (unsigned long long x, unsigned long long n)
{
Unsigned long long ans=1;
While (n> 0)
{
If (n& 1) ans=ans * x;
X=x * x;
N>=1;
}
Return ans.
}
Asked the great spirit ~
