結果

問題 No.167 N^M mod 10
ユーザー Mcpu3Mcpu3
提出日時 2018-10-07 20:29:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 144 ms / 1,000 ms
コード長 2,334 bytes
コンパイル時間 3,149 ms
コンパイル使用メモリ 77,320 KB
実行使用メモリ 41,500 KB
最終ジャッジ日時 2023-10-22 00:25:06
合計ジャッジ時間 6,398 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
40,744 KB
testcase_01 AC 106 ms
41,012 KB
testcase_02 AC 127 ms
41,304 KB
testcase_03 AC 142 ms
41,500 KB
testcase_04 AC 139 ms
41,344 KB
testcase_05 AC 105 ms
41,232 KB
testcase_06 AC 113 ms
39,780 KB
testcase_07 AC 99 ms
40,908 KB
testcase_08 AC 103 ms
41,044 KB
testcase_09 AC 107 ms
41,132 KB
testcase_10 AC 108 ms
39,772 KB
testcase_11 AC 106 ms
39,772 KB
testcase_12 AC 108 ms
41,032 KB
testcase_13 AC 108 ms
41,032 KB
testcase_14 AC 111 ms
40,908 KB
testcase_15 AC 108 ms
40,984 KB
testcase_16 AC 109 ms
41,116 KB
testcase_17 AC 108 ms
40,968 KB
testcase_18 AC 112 ms
40,908 KB
testcase_19 AC 113 ms
41,040 KB
testcase_20 AC 120 ms
40,912 KB
testcase_21 AC 98 ms
41,076 KB
testcase_22 AC 143 ms
41,352 KB
testcase_23 AC 139 ms
41,280 KB
testcase_24 AC 142 ms
41,268 KB
testcase_25 AC 144 ms
41,480 KB
testcase_26 AC 129 ms
41,176 KB
testcase_27 AC 140 ms
41,444 KB
testcase_28 AC 139 ms
41,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char N[] = new char[10002], M[] = new char[10002];
        N = sc.next().toCharArray();
        M = sc.next().toCharArray();
        sc.close();
        int N_length = N.length, M_length = M.length, tmp;
        if (M[0] == '0') System.out.print(1);
        else if (N[N_length - 1] == '0') System.out.print(0);
        else {
            if (N[N_length - 1] == '1' || N[N_length - 1] == '5' || N[N_length - 1] == '6') System.out.print(N[N_length - 1]);
            else if (N[N_length - 1] == '4' || N[N_length - 1] == '9') {
                if ((M[M_length - 1] - '0') % 2 == 0) {
                    if (N[N_length - 1] == '4') System.out.print(6);
                    else System.out.print(1);
                }
                else System.out.print(N[N_length - 1]);
            }
            else {
                if (M_length == 1) tmp = M[0] - '0';
                else tmp = 10 * (M[M_length - 2] - '0') + M[M_length - 1] - '0';
                if (N[N_length - 1] == '2') {
                    if (tmp % 4 == 1) System.out.print(2);
                    else if (tmp % 4 == 2) System.out.print(4);
                    else if (tmp % 4 == 3) System.out.print(8);
                    else System.out.print(6);
                }
                else if (N[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[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