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(循环问题)的更多相关文章

  1. HDOJ 1061 Rightmost Digit

    找出数学规律 原题: Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  2. hdoj 1061 Rightmost Digit【快速幂求模】

    Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  3. HDU 1061 Rightmost Digit --- 快速幂取模

    HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围, ...

  4. 杭电 1061 Rightmost Digit计算N^N次方的最后一位

    Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...

  5. 题解报告:hdu 1061 Rightmost Digit(快速幂取模)

    Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...

  6. 快速幂 HDU 1061 Rightmost Digit *

    Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  7. 【HDOJ】1061 Rightmost Digit

    这道题目可以手工打表,也可以机器打表,千万不能暴力解,会TLE. #include <stdio.h> #define MAXNUM 1000000001 ][]; int main() ...

  8. HDU 1061 Rightmost Digit解决问题的方法

    求大量N^N的值最右边的数字,即最低位. 它将能够解决一个简单二分法. 只是要注意溢出,只要把N % 10之后.我不会溢出,代替使用的long long. #include <stdio.h&g ...

  9. hdu 1061 Rightmost Digit

    解决本题使用数学中的快速幂取余: 该方法总结挺好的:具体参考http://www.cnblogs.com/PegasusWang/archive/2013/03/13/2958150.html #in ...

随机推荐

  1. hduTHE MATRIX PROBLEM(差分约束)

    题目请戳这里 题目大意:给一个n*m的矩阵,求是否存在这样两个序列:a1,a2...an,b1,b2,...,bm,使得矩阵的第i行乘以ai,第j列除以bj后,矩阵的每一个数都在L和U之间. 题目分析 ...

  2. Android TableLayout 常用的属性介绍及演示

    TableLayout经常用的属性是: 1.android:collapseColumns:以第0行为序,隐藏指定的列:把android:collapseColumns=0,2 意思是把第0和第2列隐 ...

  3. 使用Intent实现Activity的隐式跳转

    相比于显式Intent,隐式Intent 则含蓄了许多,它并不明确指出我们想要启动哪一个活动,而是指定了一系列更为抽象的action 和category 等信息,然后交由系统去分析这个Intent,并 ...

  4. HDU -2524 矩形A + B

    找规律题,这种题目比较巧妙,要仔细观察找出规律 1. 假设只有一行,一共有n列,那么由一个小矩形构成的矩形个数为n, 由两个小矩形构成的矩形个数为 n - 1个 .... 由 n 个小矩形构成的矩形个 ...

  5. jQuery自定义组件——输入框设置默认提示文字

    if (window.jQuery || window.Zepto) { /** * 设置输入框提示信息 * @param options * @author rubekid */ var setIn ...

  6. python运行时间计算之timeit

    timeit.timeit(stmt='pass', setup='pass', timer=<default timer>, number=1000000) stmt:statement ...

  7. 智能SQL优化工具--SQL Optimizer for SQL Server(帮助提升数据库应用程序性能,最大程度地自动优化你的SQL语句 )

    SQL Optimizer for SQL Server 帮助提升数据库应用程序性能,最大程度地自动优化你的SQL语句 SQL Optimizer for SQL Server 让 SQL Serve ...

  8. Hbase常用操作

    下面我们看看HBase Shell的一些基本操作命令,我列出了几个常用的HBase Shell命令,如 名称 命令表达式 创建表 create '表名称', '列名称1','列名称2','列名称N' ...

  9. php curl操作

    <?php // $curl=curl_init(); // $url="http://localhost/cc/get.php?lo=ccc"; // curl_setop ...

  10. asp.net执行cmd命令(包括第三方应用的命令行)

    Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = ...