結果

問題 No.167 N^M mod 10
ユーザー BantakoBantako
提出日時 2017-07-07 21:48:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 1,412 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 23,752 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 00:17:28
合計ジャッジ時間 1,260 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 0 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 0 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 0 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 0 ms
4,348 KB
testcase_14 AC 0 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 0 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
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:3:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
    3 | main(){
      | ^~~~
main.cpp: In function ‘int main()’:
main.cpp:6:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |     scanf("%s %s",N,M);
      |     ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<string.h>
main(){
    char N[10001];
    char M[10001];
    scanf("%s %s",N,M);
    int iszero = 0;
    if(strlen(M)==1){
        M[1] = M[0];
        M[0] = '0';
        M[2] = '\0';
        iszero = 1;
    }
    int base = N[strlen(N)-1] - '0';
    int exp = (M[strlen(M)-2] - '0')*10 + M[strlen(M)-1] - '0';

    int ans;
    if(exp == 0 && iszero){
        ans = 1;
    }else{
        if(base == 0){
            ans = 0;
        }
        if(base == 1){
            ans = 1;
        }
        if(base == 2){
            int num[] = {6,2,4,8};
            ans = num[exp%4];
        }
        if(base == 3){
            int num[] = {1,3,9,7};
            ans = num[exp%4];
        }
        if(base == 4){
            int num[] = {6,4};
            ans = num[exp%2];
        }
        if(base == 5){
            ans = 5;
        }
        if(base == 6){
            ans = 6;
        }
        if(base == 7){
            int num[] = {1,7,9,3};
            ans = num[exp%4];
        }
        if(base == 8){
            int num[] = {6,8,4,2};
            ans = num[exp%4];
        }
        if(base == 9){
            int num[] = {1,9};
            ans = num[exp%2];
        }
    }
    printf("%d\n",ans);

}
/*
必要桁数:2
0乗=1
n=0 -> 常に0
n=1 -> 常に1
n=2 -> 2,4,8,6
n=3 -> 3,9,7,1
n=4 -> 4,6
n=5 -> 常に5
n=6 -> 常に6
n=7 -> 7,9,3,1
n=8 -> 8,4,2,6
n=9 -> 9,1
*/
0