結果

問題 No.167 N^M mod 10
ユーザー kenji_shioya
提出日時 2016-06-21 06:54:47
言語 Java
(openjdk 23)
結果
AC  
実行時間 172 ms / 1,000 ms
コード長 687 bytes
コンパイル時間 3,837 ms
コンパイル使用メモリ 76,608 KB
実行使用メモリ 54,244 KB
最終ジャッジ日時 2024-09-22 01:34:48
合計ジャッジ時間 8,951 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise104{
  public static void main (String[] args){

    Scanner sc = new Scanner(System.in);

    String str = sc.next();
    int n = Character.getNumericValue(str.charAt(str.length() - 1));
    str = sc.next();
    if(str.equals("0")){
      System.out.println(1);
      return;
    }
    String x = "";
    if(str.length() > 1){
      x += String.valueOf(str.charAt(str.length() - 2));
    }
    x += String.valueOf(str.charAt(str.length() - 1));
    int m = Integer.parseInt(x);

    int[] choises = new int[4];
    for(int i = 1; i <= 4; i++){
      choises[i % 4] = (int)Math.pow(n, i) % 10;
    }
    System.out.println(choises[m % 4]);
  }
}
0