超大次幂思路
2015-11-10 15:27
302 查看
Description
求A^B的最后三位数表示的整数。
说明:A^B的含义是“A的B次方”
Input
输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理。
Output
对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行。
Sample Input
2 3
12 6
6789 10000
0 0
Sample Output
8
984
1
求A^B的最后三位数表示的整数。
说明:A^B的含义是“A的B次方”
Input
输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理。
Output
对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行。
Sample Input
2 3
12 6
6789 10000
0 0
Sample Output
8
984
1
#include <iostream> #include <string> #include <cmath> using namespace std; int main() { int m,n; while(cin>>m>>n) { if(m==0 && n == 0) break; int a = 0,b=0,c=0; int k = m; for(int i = 1;i<n;i++) { k*=m; a = k%10; if(k/10>0) b = k%100/10; if(k/100>0) c = k%1000/100; k = a+b*10+c*100; } //对于超大次幂,可以只保存最后三位,而不保存整个数字 cout<<k<<endl; } return 0; }
相关文章推荐
- c+(内存)
- Android开发UI之隐藏系统状态栏
- * daemon not running. starting it now * ADB server didn't ACK * failed to start daemon *
- Too many arguments to function call, expected 0, have 3
- javascript 定时器工作原理
- ViewPager轮播效果
- cameraservice如何跨进程传递video数据(准备工作)
- Build QT project in ROS
- 关于 PreparedStatement 返回值的问题
- c++(递归和堆栈)
- 办公室站队的一地鸡毛
- ios-单例模式
- grunt打包UEditor示例
- 二分查找(两行代码)
- freeswitch如何播放语音验证码(esl方式)
- DevStore教你如何玩转饥饿营销
- MFC总结(6)--- 操作Ini文件 简介
- Spring3中的@value注解
- laravel 获得url 参数
- 异常A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same