HDOJ 1061 Rightmost Digit(循环问题)
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
题意:很简单,就是输出n^n的最后一个数字时什么。
思路:前面有过一个0-9的n次方的题目,HDOJ1097题,那一题中我用代码推出了循环节,这个题目,我用的循环节全为4了.
HDOJ1097题博客链接:http://blog.csdn.net/qq_26525215/article/details/50949847
import java.util.Scanner;
public class Main{
static long db[][] = new long[10][4];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
dabiao();
// System.out.println(db[4][0]);
// System.out.println(db[4][3]);
//
long t = sc.nextLong();
while(t-->0){
int n = sc.nextInt();
int f=n%10;
int m=n%4;
//System.out.println(m);
m--;
if(m<0){
m=3;
}
System.out.println(db[f][m]);
}
}
private static void dabiao() {
for(int i=1;i<=9;i++){
for(int j=0;j<4;j++){
db[i][j]=dabiao(i,j);
//System.out.print(db[i][j]+" ");
}
//System.out.println();
}
}
private static long dabiao(long i, long j) {
long m=i;//4,3
for(int k=1;k<=j;k++){
m=(m*i)%10;
}
m=m%10;
return m;
}
}
HDOJ 1061 Rightmost Digit(循环问题)的更多相关文章
- HDOJ 1061 Rightmost Digit
找出数学规律 原题: Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- hdoj 1061 Rightmost Digit【快速幂求模】
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 1061 Rightmost Digit --- 快速幂取模
HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围, ...
- 杭电 1061 Rightmost Digit计算N^N次方的最后一位
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...
- 题解报告:hdu 1061 Rightmost Digit(快速幂取模)
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...
- 快速幂 HDU 1061 Rightmost Digit *
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 【HDOJ】1061 Rightmost Digit
这道题目可以手工打表,也可以机器打表,千万不能暴力解,会TLE. #include <stdio.h> #define MAXNUM 1000000001 ][]; int main() ...
- HDU 1061 Rightmost Digit解决问题的方法
求大量N^N的值最右边的数字,即最低位. 它将能够解决一个简单二分法. 只是要注意溢出,只要把N % 10之后.我不会溢出,代替使用的long long. #include <stdio.h&g ...
- hdu 1061 Rightmost Digit
解决本题使用数学中的快速幂取余: 该方法总结挺好的:具体参考http://www.cnblogs.com/PegasusWang/archive/2013/03/13/2958150.html #in ...
随机推荐
- Drupal 实战
<Drupal 实战> 基本信息 作者: 葛红儒 丛书名: 实战系列 出版社:机械工业出版社 ISBN:9787111429999 上架时间:2013-6-28 出版日期:2013 ...
- UITouch附加
框架 /System/Library/Frameworks/SpriteKit.framework 可用性 可用于iOS 7.0或者更晚的版本 声明于 SKNode.h 概览 重要提示:这是一个初步的 ...
- VS中批量删除cs代码中的#region和#endregion
Visual Studio中如何批量删除cs代码中的#region和#endregion,不删除它们中间的代码,只删除这两个标记及标记的注解的方法.Vs中提供了很强大的文本查找与替换功能,简单的替换只 ...
- Adding Swap Files
Adding Swap Files If you do not have free disk space to create a swap partition and you do need to a ...
- Could not reliably determine the server's fully qualified domain name
启动apache报错: [root@namenode1 ]# service httpd start Starting httpd: httpd: Could not reliably determi ...
- CSS3 2D转换
CSS3 转换 通过CSS3转换,我们能够对元素进行移动.缩放.转动.拉长或拉伸. 它如何工作? 转换是是元素改变形状.尺寸和位置的一种效果. 你可以使用2D或3D转换你的元素. 浏览器支持 属性 浏 ...
- JAVA关键词synchronized的作用
记下来,很重要. Java语言的关键字,当它用来修饰一个方法或者一个代码块的时候,能够保证在同一时刻最多只有一个线程执行该段代码. 一.当两个并发线程访问同一个对象object中的这个synchron ...
- 武汉科技大学ACM:1001: 谁不爱打牌
Problem Description BobLee最近在复习考研,但是他也喜欢打牌(有谁不爱玩牌呢?).但是作为一名ACMER,斗地主显然满足不了他的兴趣,于是他和YYD一起YY出来了一个游戏规则, ...
- ubuntu11.10(TQ210)下移植boa服务器
平台:ubuntu11.10 一.下载源码包www.boa.org boa-0.94.13.tar.gz 二.解压,在其src目录下生产makefile #tar xvfz boa-0.94.1 ...
- 纯css实现三角形
在设计界面的时候,通常需要三角形的图标,一般做法是用图片,其实也可以使用css来实现.如下: 向上的三角形 向右的三角形 向下的三角形 向左的三角形 实现它们的css分别是: .top ...