Rightmost Digit

来源:互联网 发布:mac怎么装office软件 编辑:程序博客网 时间:2024/06/16 03:11


1001

Rightmost Digit

Time Limit: 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K(Java/Other)

Total Submission(s) : 129   AcceptedSubmission(s) : 55

Font:Times New Roman | Verdana | Georgia

Font Size:← →

Problem Description

Given apositive integer N, you should output the most right digit of N^N.

Input

The inputcontains several test cases. The first line of the input is a single integer Twhich 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 testcase, you should output the rightmost digit of N^N.

Sample Input

2

3

4

Sample Output

7

6

Hint

In the firstcase, 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次方的最后一位数,将每个数的一到九次方写出来,都是四个一组循环。。

#include<iostream>

using namespace std;

int main()

{

   int num,n,m,p,i;

   cin>>num;

   for(i=0;i<num;i++)

   {

       cin>>n;

       p=n%10;//n的个位数

       m=n%4;//规律,四位一循环

       if(m==0)

       cout<<(p*p*p*p)%10<<endl;

       elseif(m==3)

       cout<<(p*p*p)%10<<endl;

       elseif(m==2)

       cout<<(p*p)%10<<endl;

       else

       cout<<p<<endl;

 

   }

   return 0;

}

 

0 0