Links: https://ac.nowcoder.com/acm/contest/3211/C
Title Description
n individuals arranged in a ring, each person to select a color from the c.
People want to choose the color of the adjacent Taurus are different
asked how many kinds of programs.
Outputs of the program results modulo 10007.
Who is in order, counted ring rotation isomorphic different schemes.
Enter a description:
输入只有一行,包含用空格分开的两个整数,表示n和c。
Output Description:
输出一行一个整数,表示答案。
Example 1
Entry
4 3
Export
18
Example 2
Entry
1000000000 100
Export
726
Explanation
对10007取模。
Remarks:
对于所有数据: 3 <= n <= 1000000000, 3 <= c <= 100
20分: c <= 3
40分: c <= 4
70分: n <= 10000
Code:
#include <bits/stdc++.h>
using namespace std;
long long n,c;
long long mod=10007;
int qpow(int a,int b)
{
int ans=1;
while(b)
{
if(b&1)
ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
int main()
{
cin>>n>>c;
long long s;
s=qpow(c-1,n);
if(n%2==0)
s+=c-1;
else
s-=c-1;
cout<<s%mod;
}