結果

問題 No.167 N^M mod 10
ユーザー tentententen
提出日時 2020-10-08 10:42:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 137 ms / 1,000 ms
コード長 614 bytes
コンパイル時間 2,282 ms
コンパイル使用メモリ 72,064 KB
実行使用メモリ 56,400 KB
最終ジャッジ日時 2023-09-27 11:46:33
合計ジャッジ時間 6,411 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
55,396 KB
testcase_01 AC 100 ms
55,336 KB
testcase_02 AC 130 ms
56,304 KB
testcase_03 AC 129 ms
54,428 KB
testcase_04 AC 133 ms
56,084 KB
testcase_05 AC 94 ms
55,404 KB
testcase_06 AC 101 ms
56,040 KB
testcase_07 AC 100 ms
55,696 KB
testcase_08 AC 99 ms
55,532 KB
testcase_09 AC 98 ms
55,384 KB
testcase_10 AC 101 ms
55,496 KB
testcase_11 AC 98 ms
55,336 KB
testcase_12 AC 104 ms
55,680 KB
testcase_13 AC 103 ms
55,616 KB
testcase_14 AC 100 ms
55,764 KB
testcase_15 AC 98 ms
55,572 KB
testcase_16 AC 100 ms
55,296 KB
testcase_17 AC 101 ms
53,964 KB
testcase_18 AC 101 ms
55,736 KB
testcase_19 AC 97 ms
55,732 KB
testcase_20 AC 102 ms
56,400 KB
testcase_21 AC 103 ms
55,716 KB
testcase_22 AC 137 ms
56,080 KB
testcase_23 AC 135 ms
56,388 KB
testcase_24 AC 131 ms
55,868 KB
testcase_25 AC 130 ms
56,096 KB
testcase_26 AC 112 ms
55,380 KB
testcase_27 AC 128 ms
56,204 KB
testcase_28 AC 131 ms
56,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] narr = sc.next().toCharArray();
		int n = narr[narr.length - 1] - '0';
		char[] marr = sc.next().toCharArray();
		if (marr.length == 1 && marr[0] == '0') {
		    System.out.println(1);
		    return;
		}
		int m = 0;
		for (int i = Math.max(0, marr.length - 3); i < marr.length; i++) {
		    m *= 10;
		    m += marr[i] - '0';
		}
		if (m == 0) {
		    m = 1000;
		}
		int ans = n;
		for (int i = 1; i < m;  i++) {
		    ans *= n;
		    ans %= 10;
		}
		System.out.println(ans);
	}
}
0