HDU OJ1061 Rightmost Digit
来源:互联网 发布:算法分析的两个方面是 编辑:程序博客网 时间:2024/05/17 23:12
HDU OJ1061 Rightmost Digit
Problem Description
Given 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的下标
#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
- HDU OJ1061 Rightmost Digit
- 杭电OJ1061-Rightmost Digit
- HDU 1061 Rightmost Digit
- hdu 1061 Rightmost Digit
- (hdu 1061)Rightmost Digit
- HDU 1061 Rightmost Digit
- HDU 1061 Rightmost Digit
- hdu rightmost digit 1061
- HDU 1061 Rightmost Digit
- HDU 1061 Rightmost Digit
- hdu 1061 Rightmost Digit
- HDU 1061 Rightmost Digit
- HDU 1061 Rightmost Digit
- HDU 1061 Rightmost Digit
- hdu 1061 Rightmost Digit
- HDU 1061 Rightmost Digit
- hdu 1061 Rightmost Digit
- hdu 1061 Rightmost Digit
- SYBASE全库备份方案
- Noip2015总结
- iOS开发学习之触摸事件和手势识别
- Objective-C中类属性的 copy, retain, assign , readonly , readwrite, nonatomic区别
- 程序员的编程艺术第一章
- HDU OJ1061 Rightmost Digit
- java 输入输出流
- c/c++素数距离问题
- 上下班同行有利于婚姻美满?
- Java 枚举类型的基础和高级用法
- Java小程序之GUI开发简单前台登录界面
- 2015noip pj 总结&反思
- Hive之UDTF
- 贪吃蛇(4)