結果

問題 No.167 N^M mod 10
ユーザー kenji_shioyakenji_shioya
提出日時 2016-06-21 06:54:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 177 ms / 1,000 ms
コード長 687 bytes
コンパイル時間 4,650 ms
コンパイル使用メモリ 77,288 KB
実行使用メモリ 57,852 KB
最終ジャッジ日時 2023-10-22 00:09:02
合計ジャッジ時間 10,055 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
57,360 KB
testcase_01 AC 131 ms
57,456 KB
testcase_02 AC 177 ms
57,852 KB
testcase_03 AC 177 ms
57,768 KB
testcase_04 AC 174 ms
57,780 KB
testcase_05 AC 131 ms
57,380 KB
testcase_06 AC 135 ms
57,336 KB
testcase_07 AC 133 ms
57,356 KB
testcase_08 AC 132 ms
57,324 KB
testcase_09 AC 131 ms
57,492 KB
testcase_10 AC 130 ms
57,484 KB
testcase_11 AC 133 ms
57,384 KB
testcase_12 AC 134 ms
57,488 KB
testcase_13 AC 134 ms
57,280 KB
testcase_14 AC 131 ms
57,692 KB
testcase_15 AC 135 ms
57,352 KB
testcase_16 AC 135 ms
57,392 KB
testcase_17 AC 133 ms
57,540 KB
testcase_18 AC 133 ms
57,316 KB
testcase_19 AC 132 ms
57,324 KB
testcase_20 AC 131 ms
57,352 KB
testcase_21 AC 131 ms
57,328 KB
testcase_22 AC 170 ms
57,784 KB
testcase_23 AC 173 ms
57,556 KB
testcase_24 AC 175 ms
55,816 KB
testcase_25 AC 176 ms
57,588 KB
testcase_26 AC 147 ms
57,316 KB
testcase_27 AC 171 ms
57,696 KB
testcase_28 AC 173 ms
57,676 KB
権限があれば一括ダウンロードができます

ソースコード

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