[luogu3197] Jailbreak

Source: Internet
Author: User

Luogu3197 thought for a long time did not think, see the solution found himself good zz. It would be all right to subtract from the illegal situation. The whole situation is that everyone is randomly chosen, in total\ (m^n\)Situation, and then consider the illegal situation, that is, any adjacent two people can not believe in the same religion, the first person has a M religion can choose, behind everyone because can not be the same as the previous one, so everyone behind the m-1 a religion can choose. So the final answer is\ (m^n-m* (m-1) ^{n-1}\)Code
#include<cstdio>#include<iostream>using namespace std;typedef long long ll;const int mod=100003;ll read() {                ll x=0, tmp=1;              char ch=getchar();           //wxywwwwwwwwwwwwwwwwwwww         while( (ch<'0') || (ch>'9') ){        if(ch=='-')tmp=-1; ch=getchar();}         while( (ch>='0')&&(ch<='9') ){           x=x*10+ch-'0';ch=getchar();              }//wxywwwwwwwwwwwwwwww                return (x*tmp);}ll qmi(ll x,ll y) {    ll ans=1;    ll now=x;    while(y) {        if(y&1) ans=ans*now%mod;        now=now*now%mod;        y>>=1;    }    return ans;}int main() {    ll m=read();    ll n=read();    cout<<(qmi(m,n)%mod-qmi(m-1,n-1)*m%mod+mod)%mod;    return 0;}

[luogu3197] Jailbreak

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.