結果

問題 No.167 N^M mod 10
ユーザー htensaihtensai
提出日時 2019-11-27 11:14:11
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 691 bytes
コンパイル時間 1,791 ms
コンパイル使用メモリ 75,040 KB
実行使用メモリ 41,524 KB
最終ジャッジ日時 2024-04-25 11:18:07
合計ジャッジ時間 6,053 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
39,712 KB
testcase_01 AC 109 ms
41,428 KB
testcase_02 AC 123 ms
41,088 KB
testcase_03 AC 144 ms
41,348 KB
testcase_04 AC 128 ms
41,340 KB
testcase_05 AC 95 ms
40,024 KB
testcase_06 AC 105 ms
41,144 KB
testcase_07 AC 107 ms
41,096 KB
testcase_08 AC 105 ms
40,956 KB
testcase_09 AC 114 ms
41,364 KB
testcase_10 AC 104 ms
41,080 KB
testcase_11 AC 96 ms
39,972 KB
testcase_12 AC 107 ms
40,820 KB
testcase_13 AC 119 ms
39,896 KB
testcase_14 WA -
testcase_15 AC 89 ms
39,432 KB
testcase_16 AC 108 ms
40,976 KB
testcase_17 AC 109 ms
41,244 KB
testcase_18 AC 108 ms
41,088 KB
testcase_19 AC 104 ms
40,976 KB
testcase_20 AC 95 ms
40,076 KB
testcase_21 AC 106 ms
39,944 KB
testcase_22 AC 135 ms
41,264 KB
testcase_23 AC 135 ms
41,248 KB
testcase_24 AC 146 ms
41,524 KB
testcase_25 AC 139 ms
41,240 KB
testcase_26 WA -
testcase_27 AC 118 ms
41,364 KB
testcase_28 AC 137 ms
41,168 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 modN = nArr[nArr.length - 1] - '0';
		char[] mArr = sc.next().toCharArray();
		if (mArr.length == 0 && mArr[0] == '0') {
		    System.out.println(1);
		    return;
		}
		if (nArr.length == 0 && nArr[0] == '0') {
		    System.out.println(0);
		    return;
		}
		int modM = 0;
		for (char c : mArr) {
		    modM *= 10;
		    modM += c - '0';
		    modM %= 8;
		}
		if (modM == 0) {
		    modM = 8;
		}
		long ans = 1;
		for (int i = 1; i <= modM; i++) {
		    ans *= modN;
		}
		ans %= 10;
		System.out.println(ans);
	}
}
0