[HNOI2008]越狱
作者:互联网
一道很水的数论题。
考虑不发生越狱的情况:第一个人可信m种宗教,第二个人只能信m - 1种宗教,第三个人也只能信m - 1种宗教,那么这割状态总数就是m * (m - 1)n - 1。
题中说求越狱状态总数,那么就是mn - m * (m - 1)n - 1,别忘取模。
1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 #include<algorithm> 5 #include<cstring> 6 #include<cstdlib> 7 #include<queue> 8 #include<stack> 9 #include<vector> 10 #include<cctype> 11 using namespace std; 12 #define enter puts("") 13 #define space putchar(' ') 14 #define Mem(a) memset(a, 0, sizeof(a)) 15 typedef long long ll; 16 typedef double db; 17 const int INF = 0x3f3f3f3f; 18 const db eps = 1e-8; 19 const ll mod = 100003; 20 //const int maxn = ; 21 inline ll read() 22 { 23 ll ans = 0; 24 char ch = getchar(), last = ' '; 25 while(!isdigit(ch)) {last = ch; ch = getchar();} 26 while(isdigit(ch)) 27 { 28 ans = ans * 10 + ch - '0'; ch = getchar(); 29 } 30 if(last == '-') ans = -ans; 31 return ans; 32 } 33 inline void write(ll x) 34 { 35 if(x < 0) putchar('-'), x = -x; 36 if(x >= 10) write(x / 10); 37 putchar(x % 10 + '0'); 38 } 39 40 ll n, m; 41 42 ll quickpow(ll a, ll b) 43 { 44 a %= mod; 45 ll ret = 1; 46 while(b) 47 { 48 if(b & 1) ret = ret * a % mod; 49 a = a * a % mod; b >>= 1; 50 } 51 return ret; 52 } 53 54 int main() 55 { 56 m = read(); n = read(); 57 write((quickpow(m, n) - m * quickpow(m - 1, n - 1) % mod + mod) % mod); enter; 58 }View Code
标签:10,ch,ll,越狱,ans,HNOI2008,include,mod 来源: https://blog.51cto.com/u_15234622/2830848