zoukankan
html css js c++ java
快速幂取模
Given a b and p, output (a^b) % p (2<=a<=100, 0<=b<=1000000000, 3<=p<=10000)
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
int
quick_power
(
int
a
,
int
b
,
int
p
)
{
int
temp
;
if
(
b
==
0
)
{
return
1
;
}
temp
=
quick_power
(
a
,
b
/
2
,
p
);
if
(
b
&
1
)
{
return
(((
temp
*
temp
)
%
p
)
*
(
a
%
p
))
%
p
;
}
else
{
return
(
temp
*
temp
)
%
p
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
a
,
b
,
p
;
while
(~
scanf
(
"%d%d%d"
,
&
a
,
&
b
,
&
p
))
{
printf
(
"%d "
,
quick_power
(
a
,
b
,
p
));
}
return
0
;
}
查看全文
相关阅读:
常用集合比较
windows和centos下安装ActiveMQ
windows + maven + eclipse
Eclipse常用插件 + Eclipse快捷键
Zookeeper + Dubbo + SpringMVC + dubbo-admin
Hession集成Spring + maven依赖通讯comm项目 + 解决@ResponseBody中文乱码
Spring结合log4j(slf4j)
nginx安装配置+集群tomcat:Centos和windows环境
Manthan, Codefest 18 (rated, Div. 1 + Div. 2) ABCDE
51nod 1483 化学变化
原文地址:https://www.cnblogs.com/sysu-zhengwsh/p/3674196.html
最新文章
系统符号
磁盘管理
网络基础
定时任务
Python高阶函数_map/reduce/filter函数
Python高阶函数
Python装饰器
Python闭包
Python函数的参数
阿里短信服务
热门文章
springboot启动插件
Shiro集成web环境[Springboot]-认证与授权
Shiro集成web环境[Springboot]-基础使用
Java环境下shiro的测试-认证与授权
shiro权限管理的框架-入门
echarts的基本使用
Maven依赖标红线,非jar包冲突问题
Nginx+Tomcat集群配置
记录一次服务器内存溢出
mongodb的安装使用,window和centos环境
Copyright © 2011-2022 走看看