結果
問題 |
No.167 N^M mod 10
|
ユーザー |
|
提出日時 | 2018-10-07 20:11:13 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,367 bytes |
コンパイル時間 | 2,219 ms |
コンパイル使用メモリ | 78,172 KB |
実行使用メモリ | 41,624 KB |
最終ジャッジ日時 | 2024-10-12 14:16:39 |
合計ジャッジ時間 | 6,884 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 WA * 2 |
ソースコード
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String N = sc.next(), M = sc.next(); sc.close(); int N_length = N.length(), M_length = M.length(), tmp; if (M.charAt(0) == '0') System.out.print(1); else if (N.charAt(N_length - 1) == '0') System.out.print(0); else { if (N.charAt(N_length - 1) == '1' || N.charAt(N_length - 1) == '5' || N.charAt(N_length - 1) == '6') System.out.print(N.charAt(N_length - 1)); else if (N.charAt(N_length - 1) == '4' || N.charAt(N_length - 1) == '9') { if ((M.charAt(M_length - 1) - '0') % 2 == 0) { if (N.charAt(N_length - 1) == '4') System.out.print(6); else System.out.print(1); } else System.out.print(N.charAt(N_length - 1)); } else { if (M_length == 1) tmp = M.charAt(0) - '0'; else tmp = 10 * (M.charAt(M_length - 2) - '0') + M.charAt(M_length - 1) - '0'; if (N.charAt(N_length - 1) == '2') { if (tmp % 4 == 1) System.out.print(2); else if (tmp % 4 == 2) System.out.print(4); else if (tmp % 3 == 3) System.out.print(8); else System.out.print(6); } else if (N.charAt(N_length - 1) == '3') { if (tmp % 4 == 1) System.out.print(3); else if (tmp % 4 == 2) System.out.print(9); else if (tmp % 4 == 3) System.out.print(7); else System.out.print(1); } else if (N.charAt(N_length - 1) == '7') { if (tmp % 4 == 1) System.out.print(7); else if (tmp % 4 == 2) System.out.print(9); else if (tmp % 4 == 3) System.out.print(3); else System.out.print(1); } else { if (tmp % 4 == 1) System.out.print(8); else if (tmp % 4 == 2) System.out.print(4); else if (tmp % 4 == 3) System.out.print(2); else System.out.print(6); } } } } }