HDOJ 1061 Rightmost Digit(循环问题)
来源:互联网 发布:cdn网络加速 编辑:程序博客网 时间:2024/05/21 03:54
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; }}
0 0
- HDOJ 1061 Rightmost Digit(循环问题)
- hdoj Rightmost Digit 1061 (数学转换&&找循环节)
- HDOJ 1061: Rightmost Digit
- hdoj 1061Rightmost Digit
- HDOJ 1061 Rightmost Digit
- HDOJ 1061 Rightmost Digit
- hdoj 1061 Rightmost Digit
- HDOJ 1061 - Rightmost Digit
- HDOJ--1061--Rightmost Digit
- HDOJ 1061Rightmost Digit
- HDOJ 1061 Rightmost Digit
- hdoj 1061 Rightmost Digit
- Rightmost Digit hdoj 1061
- HDOJ--1061--Rightmost Digit
- HDOJ 1061 Rightmost Digit
- hdoj-1061-Rightmost Digit
- HDOJ-1061 Rightmost Digit
- hdoj 1061 Rightmost Digit
- Problem K-1010
- 动态创建一组按钮,并为其绑定变量参数事件方法
- CSS实现页面布局相关属性
- 理解dropout
- 如何通过实体组件系统在Javascript中构建游戏
- HDOJ 1061 Rightmost Digit(循环问题)
- ctags为已知语言添加扩展名
- Java String
- 08.Django自定义模板,自定义标签和自定义过滤器
- 多线程:NSOperation 的基本使用
- javascript跳跃式前进(2) - 作用域及引用类型
- activity启动模式,返回上一个activity时又调用一次onCreate()方法
- 自动检测iOS网络并可跳转至设置界面设置网络
- PYTHON-进阶-编码处理小结