Rightmost Digit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 26512    Accepted Submission(s): 10193

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.

 
Author
Ignatius.L
 
 
 #include <stdio.h>
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,i,m;
int t,sum=;
scanf("%d",&n);
t=n%;
m=n%;
if(m==)
sum=t*t*t*t%;
else
{
for(i=;i<m;i++)
{
sum *= t;
}
}
printf("%d\n",sum%);
}
return ;
}
//找规律题,找到循环周期
 
/*
对于数字0~9, 它们的N次方,我们只看最后一个数字:
0^1=0; 0^2=0; 循环周期T=1;
1^1=1; 1^2=1;
循环周期T=1;
2^1=2; 2^2=4; 2^3=8; 2^4=6 2^5=2; 循环周期T=4;
3^1=3; 3^2=9; 3^3=7;
3^4=1;3^5=3; 循环周期T=4;
4^1=4; 4^2=6; 4^3=4;
循环周期T=2;

后面的大家可以自己算,会得出一个规律:
他们的循环周期只有1,2,4这三种,所以对于源代码里的b,我们可以只算b%4次就可以了,大大减少了循环的次数

*/

hdu_1061_Rightmost Digit_201311071851的更多相关文章

随机推荐

  1. E20170709-hm

    scrape   vt. 擦,刮; 擦去; 擦伤,刮破; 挖空;

  2. spring基础学习---简单配置文件

  3. Swagger 教程

    转自   Vojtech Ruzicka的编程博客 (一)Swagger和SpringFox 记录REST API非常重要.它是一个公共接口,其他模块,应用程序或开发人员可以使用它.即使你没有公开曝光 ...

  4. DFS知识点

    2019-06-01 11:14:34 加油,坚持!!! 1.  2. 3.

  5. linux命令(001) -- chkconfig

    一.准备知识 在说明chkconfig命令的用途之前,有必要先了解一下Linux系统中/etc/rc[0-6].d目录的用途. 众所周知,在Linux系统定义了7种不同的启动级别,这7种启动级别的含义 ...

  6. HDFS你一定要知道,要考的

    你肯定听过Hadoop,对就是那头奔跑的小象. Hadoop作为大数据时代代表性的解决方案被大家所熟知,它主要包含两部分内容: HDFS分布式文件存储 MapReduce分布式计算框架 前面我们分析存 ...

  7. [hihocoder][Offer收割]编程练习赛57

    1-偏差排列 斐波那契数列 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> ...

  8. Bootstrap3模态框Modal垂直居中样式

    1,Bootstrap 模态框插件Bootbox垂直居中样式: <!DOCTYPE html> <html lang="en"> <head> ...

  9. Android HTTP 数据提交

    在Android 项目中,使用HTTP协议获取数据或者处理数据,需要使用到多线程和配置相应的APP权限 1.使用线程,使用HTTP 提交数据 private Thread submitThread = ...

  10. [Java]Java分层概念

      service是业务层 action层即作为控制器 DAO (Data Access Object) 数据访问 1.JAVA中Action层, Service层 ,modle层 和 Dao层的功能 ...