結果

問題 No.167 N^M mod 10
ユーザー kuisiba
提出日時 2016-04-22 19:19:48
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 919 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 63,836 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-04 15:07:53
合計ジャッジ時間 1,444 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {

    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    string n, m;
    cin >> n >> m;
    int nn = *(--n.end()) - '0';
    int mn = *(--m.end()) - '0';
    vector<vector<int>> hitoketame{{0,0,0,0}, {1,1,1,1}, {6,2,4,8}, {1,3,9,7}, {6,4,6,4}, {5,5,5,5}, {6,6,6,6}, {1,7,9,3}, {6,8,4,2}, {1,9,1,9}};

    // mの一ケタ目mnと3(2進法で11)の&をとって、
    // 00ならhitoketame[?][0]、01ならhitoketame[?][1]、
    // 10ならhitoketame[?][2]、11ならhitoketame[?][3]
    // ?は n mod10 = nnの値
    if ((mn & 3) == 0) {
        cout << hitoketame[nn][0] << endl;
    } else if ((mn & 3) == 1) {
        cout << hitoketame[nn][1] << endl;
    } else if ((mn & 3) == 2) {
        cout << hitoketame[nn][2] << endl;
    } else {
        cout << hitoketame[nn][3] << endl;
    }
    return 0;
}
0