HDOJ1061 Rightmost Digit
来源:互联网 发布:达梦数据库下载网盘 编辑:程序博客网 时间:2024/06/07 06:52
Rightmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 60576 Accepted Submission(s): 22770
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).
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
234
Sample Output
76HintIn 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.
阶乘是指数级增长的,N(1<=N<=1,000,000,000)那么大的数肯定不能直接算。
通过输出前面一百个来观察,很容易就得知这是有规律的。
规律就是每20个一次循环,建一个长度为20的数组存放这些数就OK。
import java.util.Scanner;public class Main{private static Scanner scanner;private static int arr[];public static void main(String[] args) {dabiao();scanner = new Scanner(System.in);int cases = scanner.nextInt();while (cases-- > 0) {int n = scanner.nextInt();int res = n % 20;System.out.println(arr[res]);}}private static void dabiao() {arr = new int[20];for (int n = 0; n < arr.length; n++) {int res = n % 10;int y = res;for (int i = 1; i < n; i++) {res *= y;res %= 10;}arr[n] = res;// System.out.println(arr[n]);}}}
阅读全文
0 0
- HDOJ1061 Rightmost Digit
- HDOJ1061 Rightmost Digit(Java)
- HDOJ1061 Rightmost Digit
- hdoj1061 Rightmost Digit(简单题)
- hdoj1061 Rightmost Digit(快速幂+简单思路)
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- 51nod_1256 乘法逆元
- Mqtt精髓系列之连接建立过程
- 莱布尼兹乘积微分公式证明纠错
- 测试Mysql 事务隔离级别
- 数字图像处理matlab版第十二章
- HDOJ1061 Rightmost Digit
- 通过反射获取字段,方法,注解
- 二叉树的基本操作
- wake on lan 远程唤醒/远程开机中的所有设置细节(arp静态绑定解决长时间关机无法唤醒)
- 2015 ICPC 北京场E、F、G (计算几何)
- 动态规划专题训练
- Java并发编程:线程池的使用(非常棒,通俗易懂)
- Bitmap复用
- fastjson解析json时报错default constructor not found. class............. 原创 2014年09月10日 15:40:53 12040 实体类