hdu 1061

来源:互联网 发布:淘宝韩版春秋女装 编辑:程序博客网 时间:2024/06/06 11:37
 

#include <cstdio>

#include <cstdlib>

#define I64 __int64

 

int Fuction(I64 n) {

   int res = 1;

   I64 b = n;

   if(!n)                             // n==0, 输出1

      return 1;

   if(!(n % 10))

      return 0;

   while(b) {

      if(b & 1) {

         res *= n;

         res %= 10;                      //  要取模,否则溢出

      }

      n *= n;

      n %= 10;                            //  要取模,否则溢出

      b >>= 1;

   }

   return res % 10;

}

 

int main() {

   int t;

   I64 n;

   scanf("%d", &t);

   while(t--) {

      scanf("%I64d", &n);

      printf("%d\n", Fuction(n));

   }

   return 0;

}


 


//题目分析:求n^n的个位数,只要根据每一个数的幂的周期性规律,就行

#include<stdio.h>
int main()
{
 int n;
 int a[10][4] = {{0},{1},{6,2,4,8},{1,3,9,7},{6,4},{5},{6},

{1,7,9,3},{6,8,4,2},{1,9}},d,num;
 scanf("%d",&num);
 while(num--)
 {
    scanf("%ld",&n);
    d = n % 10;
    if(d == 0||d == 1||d == 5||d == 6)
         printf("%d\n",d);
    else if(d == 4||d == 9)
         printf("%d\n",a[d][n % 2]);
    else if(d == 2||d == 3||d == 7||d == 8)
         printf("%d\n",a[d][n % 4]);
 }
 return 0;
}

原创粉丝点击