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. Hadoop - WordCount代码示例

    文章来源:http://www.itnose.net/detail/6197823.html import java.io.IOException; import java.util.Iterator ...

  2. P3299 [SDOI2013]保护出题人

    传送门 全世界都会二分可海星-- 首先记\(sum[i]\)为\(a[i]\)的前缀和,那么第\(i\)个的答案就是\(max\{\frac{sum[i]-sum[j-1]}{x+(i-j)d}\}\ ...

  3. [Swift通天遁地]二、表格表单-(16)在表单行内嵌入日期和时间拾取器

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  4. 安科 OJ 1054 排队买票 (递归,排列组合)

    时间限制:1 s 空间限制:128 M 题目描述 有M个小孩到公园玩,门票是1元.其中N个小孩带的钱为1元,K个小孩带的钱为2元.售票员没有零钱,问这些小孩共有多少种排队方法,使得售票员总能找得开零钱 ...

  5. 什么是JavaScript的转义字符?譬如\n有什么作用?

    在JavaScript字符串中,反斜线(\)有着特殊的用途,反斜线后加一个字符,就不再表示它们的字面义了,比如\n就是一个转义字符(escape sequence),它表示的是一个换行符.在表格3-1 ...

  6. MySQL数据库笔记总结

    MySQL数据库总结 一.数据库简介 1. 数据 所谓数据(Data)是指对客观事物进行描述并可以鉴别的符号,这些符号是可识别的.抽象的.它不仅仅指狭义上的数字,而是有多种表现形式:字母.文字.文本. ...

  7. 【Leetcode 220】 Contains Duplicate III

    问题描述:判断数组中是否存在<ai aj> abs(ai - aj)<=t  && abs(i - j) <=k: 问题分析:需要一个数据结构来维护满足条件k. ...

  8. [转]linux之patch命令

    转自:http://blog.chinaunix.net/uid-9525959-id-2001542.html patch [选项] [原始文件 [补丁文件]] [功能] 给文件1应用补丁文件变成另 ...

  9. Jquery 实现列表的显示和隐藏

    本人github源码下载地址:https://github.com/liuyanpeng521/ListChange.git

  10. EasyUI系列学习(四)-Droppable(放置)

    一.创建组件 1.使用标签创建一个放置区 <div id="pox" class="easyui-droppable" style="width ...