51nod 1046 A^B Mod C (快速幂)
2015-10-12 16:18
302 查看
给出3个正整数A B C,求A^B Mod C。
例如,3 5 8,3^5 Mod 8 = 3。
Input
Output
Input示例
Output示例
例如,3 5 8,3^5 Mod 8 = 3。
Input
3个正整数A B C,中间用空格分隔。(1 <= A,B,C <= 10^9)
Output
输出计算结果
Input示例
3 5 8
Output示例
3
#include<iostream> #include<cstdio> #include<cstring> using namespace std; typedef long long ll; 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() { int a,n,mod; cin>>a>>n>>mod; cout<<mod_pow(a,n,mod)<<endl; return 0; }
相关文章推荐
- 二叉树
- CollectionUtils 判断空 和 join分隔符
- Python基础
- UITableView 多选删除功能 IOS
- 第九章、信息与通信技术系统
- UIPickerView
- UVA-1613 K-Graph Oddity (着色问题)
- Calendar使用
- 关于数据库中的BigInt的映射问题
- C++ Builder 利用Rtti访问对象中的字段值
- spring boot 起步-原型实例
- 如何将decimal转换为dbnull
- 排序算法——二分插入排序
- linux常用命令-个人收藏
- WPF之属性
- 石墨烯表亲“锡烯”问世
- NET多线程1
- 一张表格让你掌握深圳无人机供应链
- CF#305-B. Mike and Fun-暴力模拟水题
- 顺序表