結果

問題 No.167 N^M mod 10
ユーザー YamaKasaYamaKasa
提出日時 2018-07-25 21:40:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 147 ms / 1,000 ms
コード長 553 bytes
コンパイル時間 4,591 ms
コンパイル使用メモリ 74,620 KB
実行使用メモリ 57,772 KB
最終ジャッジ日時 2023-10-22 00:24:10
合計ジャッジ時間 7,977 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
57,404 KB
testcase_01 AC 119 ms
55,440 KB
testcase_02 AC 140 ms
57,296 KB
testcase_03 AC 146 ms
57,740 KB
testcase_04 AC 136 ms
57,520 KB
testcase_05 AC 105 ms
57,220 KB
testcase_06 AC 106 ms
57,408 KB
testcase_07 AC 104 ms
56,916 KB
testcase_08 AC 114 ms
57,368 KB
testcase_09 AC 108 ms
57,444 KB
testcase_10 AC 112 ms
57,404 KB
testcase_11 AC 112 ms
57,148 KB
testcase_12 AC 114 ms
57,368 KB
testcase_13 AC 112 ms
57,436 KB
testcase_14 AC 115 ms
57,656 KB
testcase_15 AC 109 ms
57,408 KB
testcase_16 AC 111 ms
57,668 KB
testcase_17 AC 109 ms
57,128 KB
testcase_18 AC 96 ms
55,824 KB
testcase_19 AC 106 ms
57,216 KB
testcase_20 AC 97 ms
56,272 KB
testcase_21 AC 94 ms
55,928 KB
testcase_22 AC 147 ms
57,772 KB
testcase_23 AC 126 ms
57,616 KB
testcase_24 AC 143 ms
57,492 KB
testcase_25 AC 122 ms
57,672 KB
testcase_26 AC 125 ms
57,712 KB
testcase_27 AC 126 ms
57,532 KB
testcase_28 AC 138 ms
57,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String N = scan.next();
		String M = scan.next();
		scan.close();
		if(M.equals("0")) {
			System.out.println(1);
			System.exit(0);
		}
		int n = Integer.parseInt(N.substring(N.length() - 1, N.length()));
		int m = 0;
		if(M.length() < 2) {
			m = Integer.parseInt(M);
		}else {
			m = Integer.parseInt(M.substring(M.length() - 2, M.length()));
		}

		m = m % 4;
		System.out.println((int)Math.pow(n, m + 4) % 10);

	}
}
0