hdu 1097 A hard puzzle
2015-09-17 16:51
381 查看
A hard puzzle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 35099 Accepted Submission(s):
12610
[align=left]Problem Description[/align]
lcy gives a hard puzzle to feng5166,lwg,JGShining and
Ignatius: gave a and b,how to know the a^b.everybody objects to this BT
problem,so lcy makes the problem easier than begin.
this puzzle describes
that: gave a and b,how to know the a^b's the last digit number.But everybody is
too lazy to slove this problem,so they remit to you who is wise.
[align=left]Input[/align]
There are mutiple test cases. Each test cases consists
of two numbers a and b(0<a,b<=2^30)
[align=left]Output[/align]
For each test case, you should output the a^b's last
digit number.
[align=left]Sample Input[/align]
7 66
8 800
[align=left]Sample Output[/align]
9
6
[align=left]Author[/align]
eddy
[align=left]Recommend[/align]
JGShining | We have carefully selected several
similar problems for you: 1170 1164 1087 1032 1062
和以前做的一道题几乎一样,上一次是求N^N的个位数,这次是求a^b的个位数,不过过程其实是一样的。。
题意:求a^b的个位数。
附上代码:
#include <iostream> using namespace std; int s[5]; void add(int t) { int i,k=1; for(i=1; i<=4; i++) //通过打表找规律,发现a^b的个位数字4个一循环,而且只需要保存个位数 { k=k*t%10; s[i]=k; } } int main() { int a,b,i,k; while(cin>>a>>b) { if(b==0) { cout<<1<<endl; continue ; } a=a%10; add(a); k=b%4; if(k==0) cout<<s[4]<<endl; else cout<<s[k]<<endl; } return 0; }
相关文章推荐
- samba-4.2.4源码安装及配置
- Handler解析
- python 基础数据类型 (一)
- 腾讯笔试题:找数目超过总数目一半的红包金额
- Oracle笔记——快速删除查询重复的数据
- java 中 log4j 的概念、作用以及如何使用
- [JS]jQuery,javascript获得网页的高度和宽度 【转】
- java 回调函数的写法
- 去除Android状态栏的广告推送
- FFmpeg与SDL双剑合璧之ubuntu
- html5预览上传图片缩略图
- HashMap的存储与实现
- Apache Camel读取配置文件
- WebRTC VideoEngine超详细教程(三)——集成X264编码和ffmpeg解码
- Java字符串转换为ASCII
- web.xml 配置中classpath: 与classpath*:的区别
- socket 设置阻塞和超时
- Third-party Modules Using Note
- 渲染和着色器
- Oracle笔记——分页查询