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 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 27 28 29 30 31 ...
rdigit = 1 4 7 6 5 6 3 6 9 0 1 6 3 6 5 6 7 4 9 0 1 4 7 6 5 6 3 6 9 0 ...
所以是以20为周期的规律。
得到这个规律,算法就变得很easy
#include<iostream>
using namespace std;
int main()
{
int rdigit[20] = {0,1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9};
int n;
cin>>n;
int res[n];
for(int i=0;i<n;i++)
{
int temp;
cin>>temp;
res[i]=rdigit[temp%20];
}
for(int i=0;i<n;i++)
{
cout<<res[i]<<endl;
}
system("pause");
return 0;
}
分享到:
相关推荐
hdu题解的答案十分简单的一个题,思路清晰,特别简单
杭电OJ(1000-1099) AC 代码
There are an odd number of 1’s among the rightmost digits, so this position is not losing. However, suppose k3 were changed to be 12. Then, there would be exactly two 1’s in each digit position, and...
文章通过深入分析rightmost及leftmost两种AIX5.3/6.1堆溢出漏洞利用方法的原理,提出了一种AIX堆溢出漏洞的新利用机制,通过CDE ToolTalk数据文件解析堆溢出漏洞对该机制进行了有效性实证
LR(1)(Left-to-Right, Rightmost derivation with 1 symbol lookahead)分析法是一种用于构建分析器的语法分析方法,通常用于分析上下文无关文法的语法结构,属于LR分析法的一种变种。它是一种强大的自底向上语法...
Make MRU tab activate instead of rightmost tab while tab closure (if MRU enabled).4. Fix folding state lost on the next startup issue.5. Make Replace-in-Files confirmation dialog modal to prevent ...
它受到堆栈溢出工作的启发( https://stackoverflow.com/questions/21354701/matlab-fprintf-to-keep-重要数字-and-rightmost- zeroes )。 这是它在行动中的一个例子>> sigfigstr(.000012431634,3) ans = '0....
如下所示: 代码如下: /* Get the rightmost substring, of the specified length, from a String object. */ String.prototype.right = function (length_) { var _from = this.length – length_; if (_from ...
Isolate the rightmost bit set to 1 Chapter 15. Create a mask for trailing zeros Chapter 16. Compute parity for a 32 bit number Chapter 17. Swap two integers variables with no additional memory ...
LR(0) parser - left to right scanning of the input and rightmost derivation of grammar symbols. <h3>LR(0) parser composed of five stages. <li> finding the FIRST set of grammar symbols. <li> ...
constant integer RIGHTMOST=2 constant integer TOPMOST=3 constant integer BOTTOMMOST=4 //-- Define default icons. -- string is_verticalpointer ='SizeWE!' string is_horizontalpointer ='...
位实用程序 用于按位操作的简单实用函数 安装 作为子模块 ...您可以手动复制bitutils.c和bitutils.h文件。 用法 ... // 0th bit is the rightmost bit int append_bit ( int n, int bit); void print_bits
-p Generates rightmost derivations used in bottom-up parsing -r Generates IR instructions from go program -r2s Generates the MIPS assembly from IR -s Generates MIPS assembly from go program 注意
6.2.1 LR Parsers and Rightmost Derivations 182 6.2.2 LR Parsing as Knitting 182 6.2.3 LR Parsing Engine 184 6.2.4 The LR Parse Table 185 6.2.5 LR(k) Parsing 187 6.3 LR(0) Table Construction 191 6.4 ...
The leftmost and rightmost slits are used to fix the viewing angle, whereas the other slits are used to increase the optical efficiency. A prototype of the proposed 1DII display is developed. Its ...
(case=11506) 7150 Missing VC6 toolbar icons have been restored (case=10126) 6980 Filtering toolbar shows the rightmost button correctly. (case=10623) 7044 <br>中文注释有乱码
94V-0 on the rightmost, nonexistent on the leftmost) may indicate that Apple is manufacturing the 5s logic boards at multiple locations. Step 13 ¶ • [size=1em]Open ses-EMI! Behold, IC treasures...
集合了 所有的 Unix命令大全 ...telnet 192.168.0.23 自己帐号 sd08077-you0 ftp工具 192.168.0.202 tools-toolss ... 各个 shell 可互相切换 ksh:$ sh:$ csh:guangzhou% bash:bash-3.00$ ... 命令和参数之间必需用空格隔...
Contents Module Overview 1 Lesson 1: Memory 3 Lesson 2: I/O 73 Lesson 3: CPU 111 Module 3: Troubleshooting Server Performance ...Troubleshooting server performance-based support calls requires ...