結果

問題 No.167 N^M mod 10
ユーザー takeya_okinotakeya_okino
提出日時 2019-08-22 20:21:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 167 ms / 1,000 ms
コード長 714 bytes
コンパイル時間 3,571 ms
コンパイル使用メモリ 86,664 KB
実行使用メモリ 57,748 KB
最終ジャッジ日時 2023-10-22 00:31:22
合計ジャッジ時間 7,515 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
57,068 KB
testcase_01 AC 130 ms
56,996 KB
testcase_02 AC 167 ms
57,520 KB
testcase_03 AC 166 ms
57,532 KB
testcase_04 AC 147 ms
57,584 KB
testcase_05 AC 127 ms
57,076 KB
testcase_06 AC 127 ms
57,268 KB
testcase_07 AC 126 ms
57,324 KB
testcase_08 AC 129 ms
57,112 KB
testcase_09 AC 129 ms
57,096 KB
testcase_10 AC 124 ms
57,328 KB
testcase_11 AC 127 ms
57,080 KB
testcase_12 AC 123 ms
57,372 KB
testcase_13 AC 126 ms
57,036 KB
testcase_14 AC 129 ms
57,748 KB
testcase_15 AC 128 ms
57,068 KB
testcase_16 AC 128 ms
57,340 KB
testcase_17 AC 130 ms
57,372 KB
testcase_18 AC 126 ms
57,304 KB
testcase_19 AC 131 ms
57,112 KB
testcase_20 AC 125 ms
57,068 KB
testcase_21 AC 128 ms
57,464 KB
testcase_22 AC 162 ms
57,400 KB
testcase_23 AC 165 ms
57,588 KB
testcase_24 AC 166 ms
57,532 KB
testcase_25 AC 163 ms
57,500 KB
testcase_26 AC 138 ms
57,268 KB
testcase_27 AC 160 ms
57,480 KB
testcase_28 AC 160 ms
57,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String n = sc.next();
    String m = sc.next();
    int d = Integer.parseInt(String.valueOf(n.charAt(n.length() - 1)));
    int e = 0;
    if(m.length() > 1) {
      e = Integer.parseInt(String.valueOf(m.charAt(m.length() - 2)) + String.valueOf(m.charAt(m.length() - 1)));
    } else {
      e = Integer.parseInt(String.valueOf(m.charAt(0)));
    }
    int e1 = (e % 4);
    if(e1 == 0) e1 = 4;
    int ans = 1;
    for(int i = 0; i < e1; i++) {
      ans = (ans * d) % 10;
    }
    if(d == 0) ans = 0;
    if((m.length() == 1) && (e == 0)) ans = 1;
    System.out.println(ans);
  }
}
0