zoukankan      html  css  js  c++  java
  • hdu 还是幂取模(费马小定理 快速幂)

    http://acm.hdu.edu.cn/diy/contest_showproblem.php?cid=18447&pid=1001

    已经过了时间不知道能不能ac 不过思路应该是没错的

    题意:给定A,B,C,计算(A^(B^C))%100000007 (已知100000007是素数)

    思路:费马小定理 :当 mod为质数 且 gcd(a,mod)=1 时  a^(p-1) %p =1

            所以此题可以先运算 mi= b^c%(mod-1)

            再算出 ans= a^mi % mod

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    #define ll __int64
    #define mod 100000007
    
    ll power_mod(ll a,ll b,ll c)
    {
        ll r=1,d=a;
        while(b)
        {
            if(b%2==1) r=(r*d)%c;
            d=(d*d)%c;
            b/=2;
        }
        return r;
    }
    int main()
    {
        ll a,b,c;
        ll mi,ans;
        while(scanf("%I64d%I64d%I64d",&a,&b,&c)!=EOF)
        {
    
            mi=power_mod(b,c,mod-1);
            ans=power_mod(a,mi,mod);
            printf("%I64d
    ",ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    1.Lucene
    docker 安装常用服务
    docker 常用命令
    05-vue中使用样式
    04-vue的事件修饰符
    03-用基本指令实现跑马灯效果
    02-vue基本指令
    01-vue分层概念MVVM
    Redis-持久化机制
    BigDecimal工具类
  • 原文地址:https://www.cnblogs.com/sola1994/p/4480309.html
Copyright © 2011-2022 走看看