結果

問題 No.167 N^M mod 10
ユーザー YamaKasa
提出日時 2018-07-25 21:40:08
言語 Java
(openjdk 23)
結果
AC  
実行時間 152 ms / 1,000 ms
コード長 553 bytes
コンパイル時間 2,247 ms
コンパイル使用メモリ 74,328 KB
実行使用メモリ 41,524 KB
最終ジャッジ日時 2024-09-22 01:48:19
合計ジャッジ時間 6,761 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

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