HDU OJ1061 Rightmost Digit
2015-11-14 15:27
281 查看
HDU OJ1061 Rightmost Digit
Problem DescriptionGiven a positive integer N, you should output the most right digit of N^N.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Output
For each test case, you should output the rightmost digit of N^N.
Sample Input
2
3
4
Sample Output
7
6
Hint
In the first case, 3 * 3 * 3 = 27, so the rightmost digit is 7.
In the second case, 4 * 4 * 4 * 4 = 256, so the rightmost digit is 6.
法一:找规律,依次列出
这里需要注意
1】x的范围,所以定义为长整形__int64d输入,%I64d输出
2】输出时,sum的下标
[code]#include <stdio.h> int main(){ __int64 x; int n,y; int sum[10][4]={{0},{1},{6,2,4,8},{1,3,9,7},{6,4},{5},{6},{1,7,9,3},{6,8,4,2},{1,9}}; scanf("%d",&n); while(n--){ scanf("%I64d",&x); y=x%10; if(y==0||y==1||y==5||y==6) printf("%d\n",sum[y][0]); else if(y==4||y==9) printf("%d\n",sum[y][x%2]); else printf("%d\n",sum[y][x%4]); } return 0; }
快速幂取余可参看
http://www.cnblogs.com/PegasusWang/archive/2013/03/13/2958150.html
相关文章推荐
- Objective-C中类属性的 copy, retain, assign , readonly , readwrite, nonatomic区别
- Deep Learning 9_深度学习UFLDL教程:linear decoder_exercise(斯坦福大学深度学习教程)
- iOS开发学习之触摸事件和手势识别
- iOS开发学习之触摸事件和手势识别
- 安卓学习笔记一 —— Activity的一些使用技巧
- OC中类属性的封装方法和类的初始化
- Noip2015总结
- C语言求数组元素中的最小值
- SYBASE全库备份方案
- SSH的正向连接和反向连接
- HTML元素 - input type=hidden
- Android的Message机制(简单小结)
- 贪吃蛇(3)
- iOS开发学习之触摸事件和手势识别
- iOS开发学习之触摸事件和手势识别
- 贪吃蛇(2)
- 环境配置正确的前提下,Run as 不出现Android Application的问题
- 安卓 URL编码 和解码注意事项
- AppStore被拒的一些原因
- RHEL 6 不关机识别新添加的scsi硬盘