算法模板:快速幂
2021/10/15 20:16:26
本文主要是介绍算法模板:快速幂,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#include<iostream> #include<cassert> #include<cstdio> #include<algorithm> #include<cstring> #include<string> #include<set> #include<queue> #include<vector> using namespace std; typedef long long ll; const int inf=0x7f7f7f7f; const int mod=1000; ll fastpow(ll base, ll power) { ll result=1; while(power>0) { if(power&1) // 如果power是奇数,就乘上现在的base result=(result*base)%mod; // 注意这个mod,真正使用时可能不需要 power>>=1; base=(base*base)%mod; } return result; } int main(){ ios::sync_with_stdio(false); cout<<fastpow(2,10); return 0; } /* */
这篇关于算法模板:快速幂的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-21订单系统资料入门教程:轻松管理你的订单
- 2024-09-21Java部署资料:新手入门教程
- 2024-09-21Java部署资料:新手入门教程
- 2024-09-21Java订单系统资料:新手入门教程与实战指南
- 2024-09-21Java管理系统资料入门教程
- 2024-09-21从零开始学习Java监控系统资料
- 2024-09-21Java就业项目资料:新手入门的必备教程
- 2024-09-21Java全端资料:初学者指南
- 2024-09-21Java全栈资料入门教程及资源汇总
- 2024-09-21Java日志系统资料入门教程