1497 取余运算

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 钻石 Diamon
 
题目描述 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

【code】

#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int b,p,k;
int f(int);
int main()
{
scanf("%d%d%d",&b,&p,&k);
int tmpb=b;
b%=k;//防止b过大
printf("%d^%d mod %d=%d\n",tmpb,p,k,f(p));
return ;
}
int f(int x)
{
if(x==)return ;//任何数的0次方模k都等于1
int tmp=f(x/)%k;//a*b%k=a%k*b%k%k;
tmp=(tmp*tmp)%k;
if(x%==)tmp=(tmp*b)%k;
return tmp;
}

最新文章

  1. 安装Windows10,Ubuntu双系统14.04LTS记录
  2. JS 的事件委托机制
  3. html基础大全(经典)
  4. Servlet.init() for servlet springMvc
  5. 16、SQL基础整理(触发器.方便备份)
  6. python知识点 2014-07-09
  7. C#堆栈原理(我有两个例子测试你到底会不会)
  8. MacOS获取辅助功能权限控制鼠标点击事件
  9. quratz启动流程
  10. nginx参数优化
  11. Redis为什么使用单进程单线程方式
  12. POJ-1180 Batch Scheduling (分组求最优值+斜率优化)
  13. spring3 hibernate4整合后无法查询数据库
  14. 【Java并发编程】之七:使用synchronized获取互斥锁的几点说明
  15. bzoj 5210(树链刨分下做个dp)
  16. RabbitMQ之发布订阅【译】
  17. 核函数(kernel function)
  18. Java常用的几种线程池
  19. 2.使用ngx_http_auth_basic_module模块为不带认证的资源添加授权
  20. #Leetcode# 951. Flip Equivalent Binary Trees

热门文章

  1. cocos2d-x 事件分发机制 ——触摸事件监听
  2. django_session
  3. Unable to satisfy the following requirements解决方式
  4. uva 1378 - A Funny Stone Game sg博弈
  5. VueJS样式绑定:v-bind
  6. http协议的Last-Modified
  7. JavaScript 日期格式化 简单有用
  8. 1.excel如何让一列的数都乘以固定值
  9. bluedroid源代码分析之ACL包发送和接收(一)
  10. remote connect openshift mysql