結果

問題 No.167 N^M mod 10
ユーザー Vir_MeL0Vir_MeL0
提出日時 2017-03-22 23:54:39
言語 Java19
(openjdk 21)
結果
AC  
実行時間 105 ms / 1,000 ms
コード長 779 bytes
コンパイル時間 1,802 ms
コンパイル使用メモリ 74,512 KB
実行使用メモリ 55,720 KB
最終ジャッジ日時 2023-10-22 00:16:00
合計ジャッジ時間 4,555 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
53,656 KB
testcase_01 AC 50 ms
52,580 KB
testcase_02 AC 100 ms
55,600 KB
testcase_03 AC 96 ms
55,336 KB
testcase_04 AC 97 ms
55,404 KB
testcase_05 AC 47 ms
53,660 KB
testcase_06 AC 49 ms
53,656 KB
testcase_07 AC 48 ms
53,660 KB
testcase_08 AC 47 ms
53,660 KB
testcase_09 AC 49 ms
53,656 KB
testcase_10 AC 47 ms
53,660 KB
testcase_11 AC 49 ms
53,656 KB
testcase_12 AC 49 ms
53,656 KB
testcase_13 AC 50 ms
53,676 KB
testcase_14 AC 47 ms
53,656 KB
testcase_15 AC 49 ms
53,652 KB
testcase_16 AC 49 ms
53,660 KB
testcase_17 AC 49 ms
53,652 KB
testcase_18 AC 47 ms
53,652 KB
testcase_19 AC 48 ms
52,592 KB
testcase_20 AC 50 ms
53,656 KB
testcase_21 AC 48 ms
53,660 KB
testcase_22 AC 99 ms
55,492 KB
testcase_23 AC 105 ms
55,692 KB
testcase_24 AC 89 ms
55,720 KB
testcase_25 AC 103 ms
55,516 KB
testcase_26 AC 86 ms
54,984 KB
testcase_27 AC 95 ms
55,436 KB
testcase_28 AC 86 ms
55,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] N = str.split("");
		int n = Integer.parseInt(N[N.length - 1]);
		str = br.readLine();
		String[] M = str.split("");
		int m = 0;
		if (M.length == 1)
			m = Integer.parseInt(M[0]);
		else {
			m = Integer.parseInt(M[M.length - 2]) * 10
					+ Integer.parseInt(M[M.length - 1]);
		}
		if (m == 0) {
			if (M.length == 1)
				System.out.println("1");
			else
				System.out.println((int) Math.pow(n, 4) % 10);
		} else {
			System.out.println((int) Math.pow(n, m % 4 + 4) % 10);
		}
	}
}
0