hdu---2035 人见人爱A^B
来源:互联网 发布:和室友网络冲突怎么办 编辑:程序博客网 时间:2024/05/18 04:28
人见人爱A^B
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25745 Accepted Submission(s): 17597
Problem Description
求A^B的最后三位数表示的整数。
说明:A^B的含义是“A的B次方”
说明:A^B的含义是“A的B次方”
Input
输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理。
Output
对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行。
Sample Input
2 312 66789 100000 0
Sample Output
89841
简单的快速幂取模:
/*
1.取后三位: Mod 取 1000
2.快速幂: 每次对指数b判断最后一位是否为1, 之后 b /= 2;
3.a = a*a%Mod;
共三步,计算出a^b对Mod取余,最后剩余的为三位数!!
*/
#include <iostream>#include <algorithm>#include <string.h>#include <math.h>#include <stdio.h>#include <queue>using namespace std;#define N 1000010#define LL long long#define Mod 1000int main(){//freopen("in.in","r",stdin);int a,b;while(scanf("%d %d",&a,&b) && a && b){int ans=1;while(b){if(b & 1){ans = ans*a%Mod;}a = a*a%Mod;b /= 2;}printf("%d\n",ans);}return 0;}
0 0
- (hdu 2035)人见人爱A^B
- HDU 2035 ( 人见人爱A^B )
- HDU 2035 人见人爱A^B
- hdu 2035人见人爱A^B
- HDU 2035 人见人爱A^B
- HDU 2035 人见人爱A^B
- HDU 2035 人见人爱A^B
- HDU 2035 人见人爱A^B
- hdu 2035 人见人爱A^B
- hdu-2035-人见人爱A^B
- HDU 2035 - 人见人爱A^B
- hdu 2035 人见人爱A^B
- [hdu 2035] 人见人爱A^B
- HDU 2035 人见人爱A^B
- HDU 2035 人见人爱A^B
- HDU 2035 人见人爱A^B
- HDU 2035 人见人爱A^B
- HDU 2035 人见人爱A^B
- 有关“MongoDB内存使用原理”
- Lex与Yacc学习(十)之Yacc库
- android多分辨率适配
- 黑马程序员—01C语言拾遗
- Httpclient
- hdu---2035 人见人爱A^B
- CSV读取类,C++ STL实现
- import com.sun.image.codec.jpeg.JPEGCodec不通过 找不到包
- 20.枚举
- 黑马程序员—02初识Object—C
- flex查询数据时弹出正在查询,查到数据自动关闭,类似进度条
- android GridView的简单示例
- android webview 缓存
- 为深入理解面向对象——大牛生小牛的问题