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\n",num1[j]);
                rea=0;
                break;
                }
              }
   if(rea){
           if(rea==2){
           y=(x-1)%4-1;
           printf("%d\n",num2[0][y]);
           }
      if(rea==3){
           if((x-1)%4==0) y=3;
             else y=(x-1)%4-1;
           printf("%d\n",num2[1][y]);
           }
        if(rea==7){
             if((x-1)%4==0) y=3;
             else y=(x-1)%4-1;
                  printf("%d\n",num2[2][y]);
           }
        if(rea==8){
              y=(x-1)%4-1;
              printf("%d\n",num2[3][y]);
           }
      if(rea==4){
           y=(x-1)%2-1;;
           printf("%d\n",num3[0][y]);
            }
        if(rea==9){
           if((x-1)%2==0) y=1;
             else y=(x-1)%2-1;
           printf("%d\n",num3[1][y]);
            }
    }
         }
return 0;
}

hd acm1061的更多相关文章

  1. ATI Radeon HD 5450 with full QE/CI Support ( 转载 )

    ATI Radeon HD 5450 with full QE/CI Support - DSDT (Contains HDMI Audio Edit Too) & AGPM included ...

  2. XPS 15 9530使用Windows10频繁发生Intel HD Graphics 4600驱动奔溃的一种解决方法

    本人使用XPS 15 9530.集成显卡为Intel HD Graphics 4600.操作系统Windows 10 Pro,使用过程当中经常会发生集成显卡奔溃的问题,错误提示如下: Display ...

  3. Radeon HD 7850 vs Radeon R9 270X

    Radeon HD 7850 vs Radeon R9 270X  HW compare   Intro The Radeon HD 7850 comes with a GPU core speed ...

  4. 电影TS、TC、SCR、R5、BD、HD等版本是什么意思

    在很多电影下载网站的影片标题中我们都能看到,比如<刺杀希特勒BD版>.<游龙戏凤TS版>等,这些英文缩写都是什么意思呢?都代表什么画质?以下就是各个版本的具体含义: 1.CAM ...

  5. stm32类型cl、vl、xl、ld、md、hd的含义

    - startup_stm32f10x_ld_vl.s: for STM32 Low density Value line devices - startup_stm32f10x_ld.s: for ...

  6. 瑞昱Realtek(Realtek HD Audio Driver)音频声卡驱动R2.49 for Win7_Vista

    不管是在高端系列主板上,还是在低端系列主板上,我们都能看到Realtek瑞昱的身影,Realtek HD Audio Driver能够支持所有的Realtek HD Audio音频驱动.Realtek ...

  7. cocos2d-x 2.0.3 设置高清模式注意事项(已移除-hd方式)

    猴子原创,欢迎转载.转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢! 原文地址: http://www.cocos2dev.com/?p=304 在cocos2d-x 2. ...

  8. %hd %d %ld %u ......

    %d 有符号10进制整数 %ld 长整型 %hd短整型%md,m指定的是输出字段的宽度,默认左补空格, 如果数据的位数小于m,则左端补以空格,若大于m,则 按实际位数输出,如: printf(&quo ...

  9. 求刷Kindle Fire HD的方法

    前几天入手了台Amazon Kindle Fire HD 其系统是经过Amazon尝试改造过的Android,用起来很不爽,想刷个CM10之类的,求教程和工具.

随机推荐

  1. SQLServer中存储过程StoredProcedure创建及C#调用(转)

    此文作为入门了解用,转自http://www.2cto.com/database/201502/378260.html 存储过程就是已经编译好的.优化过的放在数据库服务器中的一些SQL语句:可供应用程 ...

  2. nginx适配移动端

    考虑到网站的在多种设备下的兼容性,有很多网站会有手机版和电脑版两个版本.访问同一个网站URL,当服务端识别出用户使用电脑访问,就打开电脑版的页面,用户如果使用手机访问,则会得到手机版的页面. ngin ...

  3. VB中的排序问题 15个

    首次接触VB,以下就先进行VB中的排序问题                   Dim a As Integer Dim b As Integer Dim c As Integer Dim d As ...

  4. lower_bound() 与 upper_bound()

    1. lower_bound() lower_bound()是泛型算法,在使用时,需要先将序列进行排序: 作用:  函数lower_bound()在first和last中的前闭后开区间进行二分查找,返 ...

  5. mysql命令行导入和导出数据

    首先打开命令窗口,输入命令:mysql -h localhost -u selffabu -p 连接成功后,进行下面的操作 MySQL中导出CSV格式数据的SQL语句样本如下: select * fr ...

  6. 隐藏VS2013的反馈、通知和登录按钮

    Visual Studio 2013的右上角有反馈.通知.登录.快速启动等按钮,在VS2013中没有选项可以设置为隐藏. 打开注册表(开始 -> 运行 -> regedit),展开到以下路 ...

  7. Eclipse注释模板设置

    设置注释模板的入口: Window->Preference->Java->Code Style->Code Template 然后展开Comments节点就是所有需设置注释的元 ...

  8. mapreduce中reduce中的迭代器只能调用一次。其实迭代器就只能调用一次

    亲测,只能调用一次,如果想想在一次reduce重复使用迭代器中的数据,得先取出来放在list中然后在从list中取出来!!多次读取reduce函数中迭代器的数据 public static void ...

  9. mapreduce 查找共同好友

    A:B,C,D,F,E,O B:A,C,E,K C:F,A,D,I D:A,E,F,L E:B,C,D,M,L F:A,B,C,D,E,O,M G:A,C,D,E,F H:A,C,D,E,O I:A, ...

  10. jeecms搜索结果排序-二次开发

    jeecms搜索用的是apache Lucene,要实现此功能得先去学习它. 直接上代码 package com.jeecms.cms.lucene; import java.io.IOExcepti ...