题目链接

bzoj1008: [HNOI2008]越狱

题解

补集转化
变为所有可能 (\(m^n\))减去一定越狱可能(\(m * (m-1) ^ {n - 1}\))
然后就是一个快速幂了
话说这题学过乘法原理的都会做吧?
取模有毒,WA十数发

代码

#include<cstdio>
#include<algorithm>
#define LL long long 
#define mod 100003 
LL a,b; 
LL qpow(LL x,LL b) {
    LL ret = 1;x %= mod;
    for(;b;x = x * x % mod, b >>= 1) {
        if(b & 1) ret = ret * x % mod;
    } 
    return ret; 
} 
int main() {
    LL n,m; 
    scanf("%lld%lld",&m,&n);  
    printf("%lld\n",(qpow(m,n) - m * qpow((m - 1),n - 1) + mod) % mod); 
    return 0; 
} 


相关文章:

  • 2021-05-31
  • 2022-12-23
  • 2022-12-23
  • 2021-06-16
  • 2021-11-26
  • 2021-10-21
  • 2021-10-31
猜你喜欢
  • 2021-09-14
  • 2021-09-04
  • 2021-10-07
  • 2021-05-17
相关资源
相似解决方案