結果

問題 No.167 N^M mod 10
ユーザー Mcpu3Mcpu3
提出日時 2018-10-07 19:48:25
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,823 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 31,232 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 18:17:27
合計ジャッジ時間 1,045 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 WA -
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 WA -
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string.h>

int main(void)
{
    char N[10002], M[10002];
    int N_length, M_length, tmp;
    scanf("%s%s", N, M);
    N_length = strlen(N);
    M_length = strlen(M);
    if (M[0] == '0') puts("1");
    else if (M[N_length - 1] == '0') puts("1");
    else {
        if (N[N_length - 1] == '1' || N[N_length - 1] == '5' || N[N_length - 1] == '6') printf("%c", N[N_length - 1]);
        else if (N[N_length - 1] == '4' || N[N_length - 1] == '9') {
            if ((M[M_length - 1] - '0') % 2) printf("%c", N[N_length - 1]);
            else {
                if (N[N_length - 1] == '4') puts("6");
                else puts("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) puts("2");
                else if (tmp % 4 == 2) puts("4");
                else if (tmp % 4 == 3) puts("8");
                else puts("6");
            }
            else if (N[N_length - 1] == '3') {
                if (tmp % 4 == 1) puts("3");
                else if (tmp % 4 == 2) puts("9");
                else if (tmp % 4 == 3) puts("7");
                else puts("1");
            }
            else if (N[N_length - 1] == '7') {
                if (tmp % 4 == 1) puts("7");
                else if (tmp % 4 == 2) puts("9");
                else if (tmp % 4 == 3) puts("3");
                else puts("1");
            }
            else {
                if (tmp % 4 == 1) puts("8");
                else if (tmp % 4 == 2) puts("4");
                else if (tmp % 4 == 3) puts("2");
                else puts("6");
            }
        }
    }
    return 0;
}
0