結果

問題 No.167 N^M mod 10
ユーザー Mcpu3Mcpu3
提出日時 2018-10-07 19:54:00
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 1,823 bytes
コンパイル時間 1,012 ms
コンパイル使用メモリ 29,876 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 00:24:36
合計ジャッジ時間 1,829 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 (N[N_length - 1] == '0') puts("0");
    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