hdu 1061 Rightmost Digit

简介: hdu 1061 Rightmost Digit

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结果的最右边的一位数

 

思路:

只需找出循环节便可。

 

代码:

#include<stdio.h>
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
    int n,i,k=1,f[10]={0},F[10];
scanf("%d",&n);
int a=n%10,b=n%10;
f[a]=1;
F[k]=a;
for(i=0;i<n;i++)
{
a=(a*b)%10;
if(f[a]==0) {f[a]=1;k++;F[k]=a;}
else break;
}
F[0]=F[k];
printf("%d\n",F[n%k]);
}
return 0;
}
目录
相关文章
|
8月前
UVa1583 - Digit Generator
UVa1583 - Digit Generator
34 0
HDOJ(HDU) 2161 Primes(素数打表)
HDOJ(HDU) 2161 Primes(素数打表)
85 0
|
人工智能
扩展KMP - HDU 4333 Revolving Digits
 Revolving Digits Problem's Link   Mean:  给你一个字符串,你可以将该字符串的任意长度后缀截取下来然后接到最前面,让你统计所有新串中有多少种字典序小于、等于、大于原串。
782 0
容斥 - HDU 4135 Co-prime
Co-prime  Problem's Link:  http://acm.hdu.edu.cn/showproblem.php?pid=4135 推荐: 容斥原理 Mean:  给你一个区间[l,r]和一个数n,求[l,r]中有多少个数与n互素。
886 0
|
算法 Java
hdu 1796 How many integers can you find【容斥原理】
How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4674   ...
978 0
|
人工智能 BI 算法