hdu 1061 Rightmost Digit
来源:互联网 发布:coc墙升级数据 编辑:程序博客网 时间:2024/06/05 17:57
Rightmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 31559 Accepted Submission(s): 12070
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.
/*题解:
求N^N的最低位有一定规律 。当N最末尾为0 1 5 6时,最末尾一定为0 1 5 6
当N最末尾为 2 3 4 7 8 9时,其次方的最末尾具有周期性。
*/
#include<cstdio>
int main(){
int T,t;
scanf("%d",&T);
while(T--){
__int64 m;
scanf("%I64d",&m);
t=m%10;
if(t==0) printf("0\n");
if(t==1) printf("1\n");
if(t==5) printf("5\n");
if(t==6) printf("6\n");
if(t==2){
if(m%4==0) printf("6\n");
if(m%4==1) printf("2\n");
if(m%4==2) printf("4\n");
if(m%4==3) printf("8\n");
}
if(t==3){
if(m%4==0) printf("1\n");
if(m%4==1) printf("3\n");
if(m%4==2) printf("9\n");
if(m%4==3) printf("7\n");
}
if(t==4){
if(m%2==0) printf("6\n");
if(m%2==1) printf("4\n");
}
if(t==7){
if(m%4==0) printf("1\n");
if(m%4==1) printf("7\n");
if(m%4==2) printf("9\n");
if(m%4==3) printf("3\n");
}
if(t==8){
if(m%4==0) printf("6\n");
if(m%4==1) printf("8\n");
if(m%4==2) printf("4\n");
if(m%4==3) printf("2\n");
}
if(t==9){
if(m%2==0) printf("1\n");
if(m%2==1) printf("9\n");
}
}
return 0;
}
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 31559 Accepted Submission(s): 12070
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.
/*题解:
求N^N的最低位有一定规律 。当N最末尾为0 1 5 6时,最末尾一定为0 1 5 6
当N最末尾为 2 3 4 7 8 9时,其次方的最末尾具有周期性。
*/
#include<cstdio>
int main(){
int T,t;
scanf("%d",&T);
while(T--){
__int64 m;
scanf("%I64d",&m);
t=m%10;
if(t==0) printf("0\n");
if(t==1) printf("1\n");
if(t==5) printf("5\n");
if(t==6) printf("6\n");
if(t==2){
if(m%4==0) printf("6\n");
if(m%4==1) printf("2\n");
if(m%4==2) printf("4\n");
if(m%4==3) printf("8\n");
}
if(t==3){
if(m%4==0) printf("1\n");
if(m%4==1) printf("3\n");
if(m%4==2) printf("9\n");
if(m%4==3) printf("7\n");
}
if(t==4){
if(m%2==0) printf("6\n");
if(m%2==1) printf("4\n");
}
if(t==7){
if(m%4==0) printf("1\n");
if(m%4==1) printf("7\n");
if(m%4==2) printf("9\n");
if(m%4==3) printf("3\n");
}
if(t==8){
if(m%4==0) printf("6\n");
if(m%4==1) printf("8\n");
if(m%4==2) printf("4\n");
if(m%4==3) printf("2\n");
}
if(t==9){
if(m%2==0) printf("1\n");
if(m%2==1) printf("9\n");
}
}
return 0;
}
0 0
- 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
- HDU 1061 Rightmost Digit
- HDU-1061-Rightmost Digit
- C++ primer(第五版) 练习 4.22 个人code
- C++如何实现类似JAVA中加了FINAL关键字的类
- Jquery:服务器端接收客户端的多选值
- 2-09. 装箱问题模拟(20)
- BUPT2014新生暑假个人排位赛07
- hdu 1061 Rightmost Digit
- 背包问题
- 【leetcode】Best Time to Buy and Sell Stock I && II && III
- Java基础加强-java5的泛型
- POJ3373:Changing Digits(记忆化)
- cocos2d-x-3.2alpha0 如何创建新工程
- HDU 1281 棋盘游戏(匈牙利算法 二分最大匹配)
- C#:当选择DataGridView控件中的行时显示不同的颜色
- hdu 4858 项目管理 图分治 (复合算法)