Jailbreak ----------------------------------- Combined Math (Fast Power)

The prison has n rooms with consecutive numbers from 1 to n, and each room holds one prisoner.

There are m religions, and each prisoner may believe in one of them.

If the inmates in adjacent rooms believe in the same religion, a prison break may occur.

Find out how many states may be jailbroken.

The input format
consists of one line and contains two integers m and n.

Output format
The number of states that may be jailbroken.

Data range
1≤m≤108,
1≤n≤1012
Input sample:
2 3
Output sample:
6
samples Explain
all possible 6 states: (000) (001) (011) (100) (110) (111).

Analysis:
first find the number of all programs m n
and then subtract the number of programs without jailbreak m * (m-1) (n-1)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=100003;
ll n,m;
ll quick(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}
int main()
{
	scanf("%lld %lld",&m,&n);
	cout<<(quick(m,n)%MOD-m*quick(m-1,n-1)%MOD+MOD)%MOD<<endl;
 } 

Published 572 original articles · praised 14 · 10,000+ views

Guess you like

Origin blog.csdn.net/qq_43690454/article/details/105387385