HDU 1061 Rightmost Digit(分类讨论)
2014-12-07 18:16
337 查看
Rightmost Digit |
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) |
Total Submission(s): 6437 Accepted Submission(s): 1673 |
[align=left]Problem Description[/align] Given a positive integer N, you should output the most right digit of N^N. |
[align=left]Input[/align] 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). |
[align=left]Output[/align] For each test case, you should output the rightmost digit of N^N. |
[align=left]Sample Input[/align]2 3 4 |
[align=left]Sample Output[/align]7 6 |
#include<stdio.h> int main() { int n,a,i,cases,s=1; scanf("%d",&cases); while(cases>0) { scanf("%d",&n); a=n%10; if(a==1||a==0||a==5||a==6) printf("%d\n",a); if(a==2) switch(n%4) { case 1:printf("2\n");break; case 2:printf("4\n");break; case 3:printf("8\n");break; case 0:printf("6\n");break; } if(a==3) switch(n%4) { case 1:printf("3\n");break; case 2:printf("9\n");break; case 3:printf("7\n");break; case 0:printf("1\n");break; } if(a==7) switch(n%4) { case 1:printf("7\n");break; case 2:printf("9\n");break; case 3:printf("3\n");break; case 0:printf("1\n");break; } if(a==8) switch(n%4) { case 1:printf("8\n");break; case 2:printf("4\n");break; case 3:printf("2\n");break; case 0:printf("6\n");break; } if(a==4) switch(n%2) { case 1:printf("4\n");break; case 0:printf("6\n");break; } if(a==9) switch(n%2) { case 1:printf("9\n");break; case 0:printf("1\n");break; } cases--; } return 0; }
相关文章推荐
- HDU 1061 Rightmost Digit(水)
- hdu 1061 Rightmost Digit
- hdu 1061 Rightmost Digit
- HDU 1061 The rightmost digit
- HDU1061 Rightmost Digit
- HDU 1061 Rightmost Digit
- hdu 1061 Rightmost Digit
- Rightmost Digit hdu 1061
- hdu_1061_Rightmost Digit_求n^n的个位数
- Rightmost Digit HDU 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