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. Python 多线程和单线程本质应用区别

    先了解下CPU的简单运行原理: 它运行速度非常快,1s内可以运行成千上万次,一个核心可以把1s切分成成千上万个时间片段,这个核心确实同时只能运行一个任务:但是可以将多个任务交替执行,比如上一个时间片段 ...

  2. web开发中的路径问题

    http://www.cnblogs.com/tianguook/archive/2012/08/31/2665755.html 转自:http://www.blogjava.net/meil/arc ...

  3. smarty模版使用php标签,如何获取模版变量

    smarty模版使用php标签,如何获取模版变量 in: 后端程序 已经assign一个模版变量$assign,由于要做特殊的循环输出,使用for循环,因此使用到了php标签,但是php语句和模版语句 ...

  4. 如何在Windows 10 IoT Core中添加其他语言的支持,如中文

    目前很多开发者已经开始使用Windows 10 IoT来做物联网领域的开发了,目前Windows 10 IoT Core的版本支持树莓派2(以及新出的树莓派3).Minnowboard Max以及Dr ...

  5. android开发中遇到的问题汇总【九】

    244.http请求的url含有中字符时.须要Uri编码.Uri.encoder() 245.使用androidstudio时,不知道什么原因svn不见了 Android Studio missing ...

  6. 【demo练习二】:WPF依赖属性的练习

    2016-10-11 依赖属性demo小样: 要求:在窗口中点击按钮,利用设置“依赖属性”把Label和TextBox控件里的属性值进行改变. ============================ ...

  7. IE下object元素遮挡div表单

    目前遇到这样的一个问题: 我用ActiveX插件做了一个C#的播放器,要将这个插件放到web浏览器中,然后可以通过前台页面来控制视频的播放,暂停还有回放,这个时候发现object的onclick事件无 ...

  8. java代码连接本地redis数据库

    关于redis的介绍在这里就不说了.今天主要讲解,如何连接redis.连接之前.必须要做的几点: 一.安装redis.下载服务和客户端,然后 二.启动redis服务. 经过这两步的测通以后.我们只需要 ...

  9. hihoCoder #1312 : 搜索三·启发式搜索(A*, 康托展开)

    原题网址:http://hihocoder.com/problemset/problem/1312 时间限制:10000ms 单点时限:1000ms 内存限制:256MB   描述 在小Ho的手机上有 ...

  10. 由浅到深理解ROS(4)

    消息和消息类型 节点能相互传递消息,节点之间通信也是基于消息.消息类型也就是数据类型数据类型,理解消息的类型很重要,因为它决定了消息的内容.也就是说,一个话题的消息类型能告诉你该话题中每个消息携带了哪 ...