HDOJ 2035 人见人爱A^B-----二分快速求幂
2015-07-20 21:28
323 查看
http://acm.hdu.edu.cn/showproblem.php?pid=2035
//二分快速求幂
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
int main()
{
int a,b;
int s;
while(scanf("%d%d",&a,&b),a+b)
{
int cmp(int a,int b);
s=cmp(a,b);
printf("%d\n",s);
}
return 0;
}
int cmp(int a,int b)
{
int s=1;
while(b)
{
a%=1000;//取模
if(b&1)
{
s*=a;
s%=1000;
}
b>>=1;
a*=a;
}
return s;
}
//二分快速求幂
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
int main()
{
int a,b;
int s;
while(scanf("%d%d",&a,&b),a+b)
{
int cmp(int a,int b);
s=cmp(a,b);
printf("%d\n",s);
}
return 0;
}
int cmp(int a,int b)
{
int s=1;
while(b)
{
a%=1000;//取模
if(b&1)
{
s*=a;
s%=1000;
}
b>>=1;
a*=a;
}
return s;
}
相关文章推荐
- ACM学习历程—HDU 2795 Billboard(线段树)
- [Spring MVC] - Annotation验证
- 高质量C++/C编程指南
- 关于<a></a>链接的几种写法
- hdu 1166 线段树与树状数组入门 单点更新
- hdu 4149 Magic Potion
- hd-1091:A+B for Input-Output Practice (III)
- 【精】iOS6 及其以上版本自动旋转、手动强制旋转方案及布局适配
- using的几种用途
- hd-1090:A+B for Input-Output Practice (II)
- Android中适配器的使用
- linux系统管理之安装RHEL 6.4
- Cookie-网站登录-下次自动登录2
- 杭电1002 A+B Problem(II)
- 剑指off-求数组最大连续和
- 任笑萱 2015/7/8 个人文档
- 赵晓铮 2015/7/10 个人文档
- 打开jsp页面出现error解决办法
- HashSet,TreeSet和LinkedHashSet的区别
- Java — 线性查找和二分查找法