Rightmost Digit(找规律)

来源:互联网 发布:幼儿教育软件哪个好 编辑:程序博客网 时间:2024/06/06 14:03

Rightmost Digit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 47773    Accepted Submission(s): 18090


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
234
 

Sample Output
76
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.
 


#include<cstdio>  int wei(__int64 p)  {       return p%10;  }  int wei2(__int64 q)  {      return q%100;  }  int main()  {      int t;      scanf("%d",&t);      while(t--)      {          __int64 n;      scanf("%I64d",&n);       int m=wei(n);     int k=wei2(n);           int yu=k%4;//一个数的后两位是4的倍数这个数就是4的倍数     int sum=1;       if(m==0||m==1||m==5||m==6|m==9)       {           printf("%d\n",m);        }                 else       {            if(m==4)            {               printf("6\n");            }                     else          {              if(yu==0)              {                  printf("%d\n",m*m*m*m%10);              }               else               {                  for(int i=1;i<=yu;i++)                {                 sum=sum*m;                }                printf("%d\n",sum%10);               }                          }               }               }            return 0;  }


0 0