結果

問題 No.167 N^M mod 10
ユーザー Mcpu3Mcpu3
提出日時 2018-10-07 20:11:13
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,367 bytes
コンパイル時間 2,280 ms
コンパイル使用メモリ 78,136 KB
実行使用メモリ 54,652 KB
最終ジャッジ日時 2024-04-20 18:17:40
合計ジャッジ時間 6,410 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
41,224 KB
testcase_01 AC 112 ms
40,836 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 145 ms
41,084 KB
testcase_05 AC 112 ms
40,800 KB
testcase_06 AC 102 ms
40,148 KB
testcase_07 AC 122 ms
41,288 KB
testcase_08 AC 101 ms
39,944 KB
testcase_09 AC 104 ms
40,076 KB
testcase_10 AC 101 ms
40,192 KB
testcase_11 AC 115 ms
41,624 KB
testcase_12 AC 111 ms
41,568 KB
testcase_13 AC 111 ms
41,064 KB
testcase_14 AC 112 ms
41,292 KB
testcase_15 AC 117 ms
40,968 KB
testcase_16 AC 99 ms
40,180 KB
testcase_17 AC 117 ms
41,208 KB
testcase_18 AC 106 ms
40,416 KB
testcase_19 AC 110 ms
41,344 KB
testcase_20 AC 114 ms
41,144 KB
testcase_21 AC 100 ms
40,412 KB
testcase_22 AC 143 ms
41,532 KB
testcase_23 AC 142 ms
41,204 KB
testcase_24 AC 129 ms
41,588 KB
testcase_25 AC 147 ms
41,392 KB
testcase_26 AC 141 ms
41,196 KB
testcase_27 AC 132 ms
41,516 KB
testcase_28 AC 148 ms
41,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
                }
            }
        }
    }
}
0