結果

問題 No.167 N^M mod 10
ユーザー Bantako
提出日時 2017-07-07 21:38:10
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,188 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 23,552 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-06 10:03:49
合計ジャッジ時間 1,007 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
    if(strlen(M)==1){
        M[1] = M[0];
        M[0] = '0';
        M[2] = '\0';
    }
    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){
        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,6,9,7};
            ans = num[exp%5];
        }
        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);

}
0