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. C#写csv文件

    1.在项目中经常需要把报表下载为csv格式的文件,如何在C#中写csv文件,以下为一个简化的例子,不使用任何控件,旨在说明用法. 前端view 下载结果 2.创建一个MVC项目(Intranet Ap ...

  2. IBM Rational Appscan使用之扫描结果分析

    转自:http://www.nxadmin.com/penetration/825.html 之前有IBM Rational Appscan使用详细说明的一篇文章,主要是针对扫描过程中配置设置等.本文 ...

  3. Mysql-Proxy实现mysql读写分离、负载均衡 (转)

    在mysql中实现读写分离.负载均衡,用Mysql-Proxy是很容易的事,不过大型处理对于性能方面还有待提高,主要配置步骤如下: 1.1. mysql-proxy安装 MySQL Proxy就是这么 ...

  4. mysql中去重复记录

    Distinct 这个只能放在查询语句的最前面 参考 : https://www.cnblogs.com/lushilin/p/6187743.html

  5. ppm\pgm格式

    PGM 是便携式灰度图像格式(portable graymap file format),在黑白超声图像系统中经常使用PGM格式的图像.文件的后缀名为".pgm". PGM格式图像 ...

  6. org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'

    异常原因: 1.mockito的jar包中缺少方法 2.mock方法的时候,返回的是对象,而对象没有重写equals方法 3.mock的实例方法调用方法错误 解决方法: 1.用powermock中的a ...

  7. Android Studio 使用笔记:文件查询方法总结

    搜索单词 Windows: Ctrl + F Mac   : Cmd + F 会在当前激活的文件上查询输入的关键字,以高亮显示 跳转行 Windows: Ctrl + L Mac   : Cmd + ...

  8. php 如何获取一个json文件

    function showupversion(){ #获取平台类型 $type='android'; #读取文件的路径 $url="D:/WWW/gm_lequ/gm_lequ"; ...

  9. Java多线程编程总结一:多线程基本概念

    Java多线程编程总结一 – 初识多线程 进程.多进程.线程.多线程的概念 进程(process):CPU的执行路径.通俗的说就是系统中正在运行的程序.比如我们打开了浏览器.QQ等等,这些程序一旦被打 ...

  10. JQuery基础知识--方便忘记时查看

    第一次写博客,不多说废话,实用为先.如有不对,请多指正. JQuery api 第一步引入JQuery库. <script type="text/javascript" sr ...