結果
問題 |
No.167 N^M mod 10
|
ユーザー |
![]() |
提出日時 | 2017-03-22 23:42:26 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 699 bytes |
コンパイル時間 | 1,663 ms |
コンパイル使用メモリ | 74,336 KB |
実行使用メモリ | 52,448 KB |
最終ジャッジ日時 | 2024-07-05 17:51:34 |
合計ジャッジ時間 | 3,807 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 11 WA * 2 RE * 14 |
ソースコード
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(); int n = Integer.parseInt(str) % 10; 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) System.out.println("1"); else { int ans = n; for (int i = 1; i < m; i++) ans = (ans * n) % 10; System.out.println(ans); } } }