zoukankan      html  css  js  c++  java
  • 【BZOJ】【1008】【HNOI】越狱

    快速幂


      大水题= =

      正着找越狱情况不好找,那就反过来找不越狱的情况呗……

      总方案是$m^n$种,不越狱的有$m*(m-1)^{n-1}$种= =

      负数搞搞就好了……

      莫名奇妙地T了好几发……

     1 /**************************************************************
     2     Problem: 1008
     3     User: Tunix
     4     Language: C++
     5     Result: Accepted
     6     Time:0 ms
     7     Memory:804 kb
     8 ****************************************************************/
     9  
    10 //BZOJ 1008
    11 #include<cstdio>
    12 typedef long long LL;
    13 const int P=100003;
    14 LL Pow(LL a,LL b,LL P){
    15     LL r=1;
    16     for(;b;b>>=1,a=a*a%P) if (b&1) r=r*a%P;
    17     return r;
    18 }
    19 int main(){
    20     LL n,m;
    21     scanf("%lld%lld",&m,&n);
    22     LL ans=Pow(m,n,P)-Pow(m-1,n-1,P)*m%P;
    23     if (ans<0) ans+=P;
    24     printf("%lld
    ",ans);
    25     return 0;
    26 }
    View Code
  • 相关阅读:
    rsync特性
    01 什么是爬虫
    celery的使用
    redis的使用
    GIT使用大全
    多项式的高级运算
    SP1557 GSS2
    题解 CF997E 【Good Subsegments】
    P3920 [WC2014]紫荆花之恋
    题解 P3750 【[六省联考2017]分手是祝愿】
  • 原文地址:https://www.cnblogs.com/Tunix/p/4409228.html
Copyright © 2011-2022 走看看