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. PJISP 修改 消息头Fromto字段

    项目需求,需要修改sip信令消息头中Fromto字段,完成此功能需要修改sip库(PJSIP)源码,具体如下: PJSIP 消息头 Formto  字段默认的格式是sip:平台@平台IP地址,例如si ...

  2. LINQ中Aggregate的用法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. windows小游戏之扫雷技巧

    通过单击即可挖开方块.如果挖开的是地雷,则您输掉游戏. 如果方块上出现数字,则表示在其周围的八个方块中共有多少颗地雷.

  4. 获取、增加、修改、删除sqlserver字段描述及快速查看表字段与描述

    先看添加与删除字段描述 EXEC sys.sp_addextendedproperty @name = N'MS_Description', --添加Type字段说明 @value = N'屏蔽类型对 ...

  5. 使用nginx搭建https服务器(转)

    最近在研究nginx,整好遇到一个需求就是希望服务器与客户端之间传输内容是加密的,防止中间监听泄露信息,但是去证书服务商那边申请证书又不合算,因为访问服务器的都是内部人士,所以自己给自己颁发证书,忽略 ...

  6. Spring Boot - 配置信息后处理

    最近在做项目的过程中,PSS提出配置文件中类似数据库连接需要的用户名.密码等敏感信息需要加密处理(之前一直是明文的). 为了快速完成任务,网上搜刮到jasypt包,也有相应的starter,使用方法可 ...

  7. HDFS源码分析数据块复制监控线程ReplicationMonitor(二)

    HDFS源码分析数据块复制监控线程ReplicationMonitor(二)

  8. k8s调度-指定node

    1.给node加标签 kubectl label nodes k8s-slave2 slave= 2.查看标签 [root@k8s_master centos7]# kubectl describe ...

  9. 解决ubuntukylin下各种终端字母重叠的方案

    ubuntukylin14.04什么都挺好定符合中国人的使用习惯的,可是就是终端字母重叠的问题特别严重;(事实上ubuntu14.04也存在这个问题) 导致非常多非常好用的终端都使用不了,像guake ...

  10. GitHub 小试牛刀(踩坑记录)

    首先要在GitHub上创建好远程仓库,把README,LISCENCE,.gitignore三个文件在远程仓库初始化好. 然后在创建本地仓库,先要cd到自己的项目目录下,然后: $ git init ...