快速幂取模
来源:互联网 发布:blct升级数据 编辑:程序博客网 时间:2024/06/05 19:42
非递归法:
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
int a,b,c,s=1;
cin>>a>>b>>c;
a=a%c;
while(b){
if(b%2==1) s=s*a%c;
a=a*a%c;
b/=2;
}
printf("%d\n",s);
return 0;
}
递归法:
#include<stdio.h>
int ksm(int a,int b,int c){
int ans=1;
a=a%c;
while(b>0){
if(b%2==1) ans=ans*a%c;
b/=2;
a=a*a%c;
}
return ans;
}
阅读全文
0 0
- 快速幂,快速幂取模
- 快速幂 + 快速幂取模
- 快速幂 快速幂取模
- 快速幂 快速幂取模
- 【快速幂】【快速幂取模】
- 快速幂,快速幂取模,矩阵快速幂
- 快速幂取模
- 快速幂取模
- 快速幂取模
- 快速幂取模
- 快速幂取模
- 快速幂取模
- 快速幂取模
- 快速幂取模
- 快速幂取模
- 快速幂取模
- 快速幂取模
- 快速幂取模
- lintcode 3:统计数字
- Android中TextView实现富文本展示效果
- java
- 理解node中的require和exports
- coursera Machine Learning 第六周 测验quiz2答案解析 Machine Learning System Design
- 快速幂取模
- java大数据
- PHP入门-变量声明与使用
- 新老系统迁移及整合方案
- 数据结构之归并排序(java)
- linux CentOS 7 安装 java1.8
- Android网络请求-sign参数的设置
- 日常咸鱼记录17/12/13,更新Vmware Tools
- C++ 关于sort