**一道超6的题目**
杭电1061Rightmost 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.
1;一道超6的题目,还早队友找到的并ac了的。当时听了他的分析我是顿时666的感觉哦。现在突然想起这个题目,所以发一篇博客,留个印象,以后复习好看看。队友的神操作啊。
2;题目意思就是求一个数n的n阶乘的尾数是好多。反正当时我是晕晕的,后来听了他的解释之后才长了记性。有的题是要找规律的。
只算出尾数。
尾数是0的那么他的结果肯定还是0啊
尾数是1的也是同理啊;
2;=======应该是4或者6;
2*2=4;
2*2*2=8;
2*2*2*2=6;
2*2*2*2*2=2;
2*2*2*2*2*2=4;开始循环了,
再看2肯定是偶数次相乘,则只有4或者6了。然而这又要怎么区别呢?
是不是答案是6的那么必然相乘的个数是4的倍数,则(n%100)%4==0;
我们先跳过去看8,一样的分析,是不是发现8和2是一样的条件输出;
则可以写出代码
if(q==8||q==2)
{
if(p%4==0) printf("6");
else printf("4");
}
3======3或则7;分析就和上面2的是一样的。
if(q==3)
{
if((p-1)%4==0) printf("3");
else printf("7");
}
其余的都是这样的。
可以要注意的两点,
1;是有两个输出情况的,要对4取余的,是用n%100的数去取余4;因为只要这里满足那么这个数也会满足的。100是4的倍数;
2;奇数的时候要减一再取余4;
看以摆代码了。
#include<stdio.h>
int main()
{
long long n,k,p,q;
scanf("%lld",&k);
while(k--)
{
scanf("%lld",&n);
p=n%100,q=n%10;
if(q==5||q==6||q==0||q==1)
printf("%lld",q);
if(q==4)
printf("6");
if(q==9)
printf("9");
if(q==8||q==2)
{
if(p%4==0) printf("6");
else printf("4");
}
if(q==3)
{
if((p-1)%4==0) printf("3");
else printf("7");
}
if(q==7)
{
if((p-1)%4==0) printf("7");
else printf("3");
}
printf("\n");
}
return 0;
}