BZOJ 1008 jailbreak

Face questions

The meaning of problems

  All of length \ (n-\) , range of \ (1 \ sim m \) sequence, which satisfy the present request sequence number is equal to two adjacent elements. To \ (100003 \) to take over.

answer

  Convert ideas, seeking to limit the number of sequences is not satisfied. Let the neighbors is not equal to the sequence, the determined value of the first element, after each element does not last as long as an element can be the same, that is to say in addition to the first one, the remaining \ (n-1 \) bits are \ (m-1 \) species emulated, so there \ (m (m-1) ^ {n-1} \) sequence number does not meet the requirements. Total sequence \ (n-m ^ \) , the answer is \ (m ^ nm (. 1-m). 1-n-^ {} \) . With fast power evaluated.


Code

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
const ll mod=1e5+3;
ll qpow(ll a,ll b){
    ll ans=1;
    while (b){
        if (b&1) ans=ans*a%mod;
        a=a*a%mod; b>>=1;
    }
    return ans;
}
int main(){
    ll n,m,ans;
    scanf("%lld%lld",&m,&n);
    ans=(qpow(m,n)-m*qpow(m-1,n-1))%mod;
    printf("%lld\n",(ans+mod)%mod);
    return 0;
}

Guess you like

Origin www.cnblogs.com/Kilo-5723/p/12033578.html