Rightmost Digit
来源:互联网 发布:中山广电网络营业厅 编辑:程序博客网 时间:2024/06/14 05:02
Rightmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9245 Accepted Submission(s): 2327Problem 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).
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
234
Sample Output
76HintIn 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.#include<stdio.h>main(){ int n,cas,m; scanf("%d",&cas); while(cas--) { scanf("%d",&n); m=n%10; if(m==0||m==1||m==5||m==6) printf("%d\n",m); if(m==2) { if (n%4==1) printf("2\n"); if (n%4==2) printf("4\n"); if (n%4==3) printf("8\n"); if (n%4==0) printf("6\n"); } if(m==3) { if (n%4==1) printf("3\n"); if (n%4==2) printf("9\n"); if (n%4==3) printf("7\n"); if (n%4==0) printf("1\n"); } if(m==7) { if (n%4==1) printf("7\n"); if (n%4==2) printf("9\n"); if (n%4==3) printf("3\n"); if (n%4==0) printf("1\n"); } if(m==8) { if (n%4==1) printf("8\n"); if (n%4==2) printf("4\n"); if (n%4==3) printf("2\n"); if (n%4==0) printf("6\n"); } if (m==4) { if (n%2==1) printf("4\n"); if (n%2==0) printf("6\n"); } if (m==9) { if (n%2==1) printf("9\n"); if (n%2==0) printf("1\n"); } }}
0 0
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- A+B for Input-Output Practice (I)
- Buildings
- DDL、DML和DCL的区别与理解
- Higher Math
- HHVM和PHP7新性能
- Rightmost Digit
- 关于android studio 2.3无法安装apk的解决办法
- Vowel Counting
- mysql商业版和社区版的区别
- Lowest Bit
- Text Reverse
- 今年暑假不AC
- php中的 session_start()是做什么的?
- 根据角度获取圆的坐标点