人见人爱A^B
2017-01-24 02:19
253 查看
人见人爱A^B
2016年9月27日 19:00新浪博客
删除
Description
求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
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; int main() { int n,m; while(~scanf("%d %d",&n,&m)) { if(n==0&&m==0)//题目中若要求了结束条件要注明 break; int sum=1; for(int i=0;i<m;i++) { sum=(sum*n)%1000; } printf("%d\n",sum%1000); } return 0; }
相关文章推荐
- C#编程实现取整和取余的方法
- shell整除取余
- 1.m分解阶乘之和
- 2.几种递推数
- 3.欧拉函数
- 4.快速幂模m算法
- 5.扩展欧几里得&&中国剩余定理
- 6.数论_web
- Project Euler Problem 387 - Harshad Numbers - 深度优先
- 编程之美2015初赛A
- [容斥+莫比乌斯]bzoj2440_完全平方数
- HDU 3388 与m,n 互质的第k个整数
- 数论题集
- 原根
- 阶与原根学习笔记
- HDU 1299 Diophantus of Alexandria
- Leftmost Digit(HDU 1060)
- Rightmost Digit(HDU 1061)
- ZS and The Birthday Paradox
- Python-在奇数中寻找素数