Nowhere P 题解
_DeepBlue_ · · 题解
题目传送门
这就是一个快速幂版子题。
显然的,第一个数只有
代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
int n,m;
ll qpow(ll a,int b){
ll ans=1;
while(b){
if(b&1)ans=ans*a%mod;
b>>=1;
a=a*a%mod;
}
return ans;
}
int main(){
cin>>n>>m;
cout<<qpow(m-2,n-1)*(m-1)%mod;
return 0;
}