当前位置:
首页 >
数论练习(1)——取余运算(快速幂)
发布时间:2024/4/17
50
豆豆
生活随笔
收集整理的这篇文章主要介绍了
数论练习(1)——取余运算(快速幂)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1497 取余运算
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description
输入b,p,k的值,编程计算bp mod k的值。其中的b,p,k*k为长整型数(2^31范围内)。
输入描述 Input Descriptionb p k
输出描述 Output Description输出b^p mod k=?
=左右没有空格
样例输入 Sample Input2 10 9
样例输出 Sample Output2^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; }
转载于:https://www.cnblogs.com/cunyusup/p/8401747.html
总结
以上是生活随笔为你收集整理的数论练习(1)——取余运算(快速幂)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Oracle拆分字符串函数与执行调用
- 下一篇: gitHub网站上常见英语翻译