HDOJ-ACM1097(JAVA) A hard puzzle

这道题就是HDOJ的1061的变形:

1061 :求n的n次方的个位数 http://www.cnblogs.com/xiezie/p/5596779.html

1097 :求n的m次方的个位数

因此,就不在这里赘述了

以下是JAVA实现:

import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
        while(scan.hasNext()){
            int n = scan.nextInt();
            int m = scan.nextInt();
            int rightMostDigitOfN = n%10;
            ArrayList<Integer> rightMostDigits = arrays.get(rightMostDigitOfN);
            int size = rightMostDigits.size();
            if(size == 1){
                System.out.println(rightMostDigitOfN);
            }else{
                System.out.println(rightMostDigits.get((m-1)%size));
            }
        }
        scan.close();
    }

    static ArrayList<ArrayList<Integer>> arrays  = getRightMostDigitArray();

    static ArrayList<ArrayList<Integer>> getRightMostDigitArray(){
        ArrayList<ArrayList<Integer>> arrays = new ArrayList<>();
        for(int i = 0 ; i != 10 ; i ++){
            ArrayList<Integer> integers = new ArrayList<>();
            integers.add(i);
            int n = 2;
            while(true){
                int rightMostDigit = (int) (Math.pow(i, n)%10);
                if(rightMostDigit==i){
                    break;
                }else{
                    integers.add(rightMostDigit);
                }
                n++;
            }
            arrays.add(integers);
        }
        return arrays;
    }

}
时间: 2024-10-01 04:26:58

HDOJ-ACM1097(JAVA) A hard puzzle的相关文章

HDOJ 1000 java

第一次做hdoj 试了好几次才通过 发现主类的名字必须是Main import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner= new Scanner(System.in); while(scanner.hasNext()) { int A=scanner.nextInt(); int B=scanner.nextInt(); System.out.p

ACM--大数阶乘--HDOJ 1042--N!--Java

HDOJ题目地址:传送门 N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 74952    Accepted Submission(s): 21832 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Inp

HDOJ 1001 java

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner= new Scanner(System.in); int sum,n; while(scanner.hasNext()) { n=scanner.nextInt(); sum=0; for(int i=1;i<=n;i++) { sum+=i; } System.out.println(sum

HDOJ 1002 java

import java.math.BigInteger; import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner= new Scanner(System.in); int n=scanner.nextInt(); for(int i=1;i<=n;i++) { BigInteger a=sca

hdoj 1007 java MLE通不过

参考网上的一个算法,但是一直都是MLE,实在是想不出来什么办法了. 参考博客:编程之美寻找最近点对 import java.util.Arrays; import java.util.Scanner; public class Main { public static int N=100000; public static int[] list=new int[N]; public static Point[] ptns=new Point[N]; public static float MAX

【HDOJ 1002】A + B Problem II

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 238517    Accepted Submission(s): 45969 Problem Description I have a very simple problem for you. Given two integers A and B, you

hdoj 1097 A hard puzzle (找规律)

A hard puzzle                            T   ime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29231    Accepted Submission(s): 10494 Problem Description lcy gives a hard puzzle to feng5166,lwg,JG

HDOJ 5411 CRB and Puzzle 矩阵快速幂

直接构造矩阵,最上面一行加一排1.快速幂计算矩阵的m次方,统计第一行的和 CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 133    Accepted Submission(s): 63 Problem Description CRB is now playing Jigsaw Puzzle. There

Java GUI 基础 Eight Puzzle (拼图游戏)

很简单使用java GUI 制作一个简单的拼图游戏 // main package HW1; import java.io.IOException; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class HW1 extends JFrame{ /** * */ public HW1_0586(String s