HDU 1061 Rightmost Digit
来源:互联网 发布:淘宝买知网账号靠谱吗 编辑:程序博客网 时间:2024/05/18 02:30
Rightmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19450 Accepted Submission(s): 7504
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).
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.
Author
Ignatius.L
分析:找规律即可,像最后位是1的,不管多少个数相乘都是1,然后依次往下找,b[]代表每个数循环的个数
代码:
#include<stdio.h>int a[10][5]={{0},{1},{2,4,8,6},{3,9,7,1},{4,6},{5},{6},{7,9,3,1},{8,4,2,6},{9,1}};int b[10]={1,1,4,4,2,1,1,4,4,2};int main(){ int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); int m; m=n%10; if(n%b[m]==0) printf("%d\n",a[m][b[m]-1]); else printf("%d\n",a[m][n%b[m]-1]); } return 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
- Bit Twiddling Hacks
- win32 pv操作 读者写者问题
- Ubuntu添加BT5软件源
- VB中Split函数的作用和用法(字符串用逗号分割)
- SGU 364 Lemmings Dijkstra
- HDU 1061 Rightmost Digit
- 采用vb以十六进制的形式读取文本文档数据
- GL_MODELVIEW与GL_PROJECTION的区别
- PADS备忘录
- 《编程珠玑》读书笔记4------------第四章部分习题及个人答案
- Objective-c中的委托
- 应用服务器学习笔记
- Xcode调试技巧之二 crash之后的定位问题
- poj 1195 Mobile phones