結果

問題 No.167 N^M mod 10
ユーザー tetsuzuki1115
提出日時 2018-02-15 00:24:41
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 812 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 80,412 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 11:27:31
合計ジャッジ時間 1,709 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    string N,M;
    cin >> N >> M;

    if ( M == "0" ) { cout << 1 << endl; return 0; }

    int a = N[N.length()-1] - '0';
    int b[4];
    
    int n = a;
    for ( int i = 0; i < 4; i++ ) {
        b[i] = n;
        n *= a;
        n %= 10;
    }

    string s;
    for ( int i = M.length()-1; i >= 0; i-- ) {
        s += M[i];
        if ( s.length() == 2 ) { break; }
    }
    if ( s.length() == 2 ) { swap( s[0], s[1] ); };
    int m = stoi(s);

    cout << b[m%4 - 1] << endl;

    return 0;
}
0