zoukankan      html  css  js  c++  java
  • 数论练习(1)——取余运算(快速幂)

    1497 取余运算

     

     时间限制: 1 s
     空间限制: 128000 KB
     题目等级 : 钻石 Diamond
     
     
    题目描述 Description

    输入b,p,k的值,编程计算bp mod k的值。其中的b,p,k*k为长整型数(2^31范围内)。

    输入描述 Input Description

    b p k 

    输出描述 Output Description

    输出b^p mod k=?

    =左右没有空格

    样例输入 Sample Input

    2  10  9

    样例输出 Sample Output

    2^10 mod 9=7

    数据范围及提示 Data Size & Hint
     
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long  ll;
    
    const int inf = 0x3f3f3f3f;
    const int maxn = 40000 + 20;
    const int moder = 1e9 + 7;
    const int K = 256;
    
    ll mod_pow(ll x,ll n,ll mod)
    {
        ll res = 1;
        while(n > 0)
        {
            if(n & 1) res = (res * x) % mod;
            x = (x * x) % mod;
            n >>= 1;
        }
        return res;
    }
    
    int main()
    {
        ll b,p,k;
        scanf("%lld%lld%lld",&b,&p,&k);
        cout << b << "^" << p << " " << "mod " << k <<"=" <<mod_pow(b,p,k);
        return 0;
    }
  • 相关阅读:
    团队开发-第一阶段冲刺-10
    团队开发-第一阶段冲刺-09
    Spring(三)
    第五周总结
    Spring(一)
    程序员修炼之道:从小工到专家阅读笔记1
    MyBatis(三)
    MyBatis(二)
    MyBatis
    第四周总结
  • 原文地址:https://www.cnblogs.com/cunyusup/p/8401747.html
Copyright © 2011-2022 走看看