• hd acm1061


    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.
     
    Sample Way
     
    最右边的数字是有周期的,将他们打印一遍就可以看出周期。另外代码中红色部分是注意的地方。

    #include <stdio.h>
    #include <stdlib.h>

    int main()
    {
      int num1[4]={0,1,5,6};
      int num2[4][4]={{4,8,6,2},{9,7,1,3},
               {9,3,1,7},{4,2,6,8}};
      int num3[2][2]={{6,4},{1,9}};
      int n,i,rea,j;
      long x,y;
      scanf("%d",&n);
      for(i=0;i<n;i++){
        scanf("%ld",&x);
        rea=x%10;
          for(j=0;j<4;j++){
            if(num1[j]==rea){
                    printf("%d ",num1[j]);
                    rea=0;
                    break;
                    }
                  }
       if(rea){
               if(rea==2){
               y=(x-1)%4-1;
               printf("%d ",num2[0][y]);
               }
          if(rea==3){
               if((x-1)%4==0) y=3;
                 else y=(x-1)%4-1;
               printf("%d ",num2[1][y]);
               }
            if(rea==7){
                 if((x-1)%4==0) y=3;
                 else y=(x-1)%4-1;
                      printf("%d ",num2[2][y]);
               }
            if(rea==8){
                  y=(x-1)%4-1;
                  printf("%d ",num2[3][y]);
               }
          if(rea==4){
               y=(x-1)%2-1;;
               printf("%d ",num3[0][y]);
                }
            if(rea==9){
               if((x-1)%2==0) y=1;
                 else y=(x-1)%2-1;
               printf("%d ",num3[1][y]);
                }
        }
             }
    return 0;
    }

  • 相关阅读:
    互联网史上第一约架 罗永浩对话王自如
    The Open Group Announces Launch of the TOGAF® Standard, 10th Edition
    从零开始学PHP系列(0.1)语法简记
    QtQt使用鼠标钩子Hook(支持判断按下、弹起、滚轮方向)
    QtQPropertyAnimation的使用(支持放大、移动、透明动画)
    OsgOsgEarth加载在线地图(myMap.earth)
    关于UE4对象静态/动态的销毁问题整理(AddToRoot、TWeakObjectPtr)
    cesanta elk安装及测试
    RocketMQ的原理和实战!
    LINQ:GroupBy
  • 原文地址:https://www.cnblogs.com/clljs/p/7425179.html
Copyright © 2020-2023  润新知