結果

問題 No.167 N^M mod 10
ユーザー kpinkcatkpinkcat
提出日時 2023-11-04 10:55:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 947 bytes
コンパイル時間 1,164 ms
コンパイル使用メモリ 109,692 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-04 10:55:29
合計ジャッジ時間 2,369 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<math.h>
#include<bitset>
using ll = long long;
using namespace std;

int div(string s, int div){
    int i;
    i = stoi(s.substr(0, 1));
    s = s.substr(1);
    while (s.size()){
        i *= 10;
        i += stoi(s.substr(0, 1));
        s = s.substr(1);
        i %= div;
    }
    return i;
}

int main(){
    string n, m;
    cin >> n >> m;
    int t1 = n[n.size()-1] - '0';
    ll r, ans = t1;
    vector<ll> modulo{1, 1, 4, 4, 2, 1, 1, 4, 4, 2};
    if (m == "0"){
        cout << 1 << endl;
        return 0;
    }
    if (modulo[t1] == 1) {
        cout << n[n.size()-1] << endl;
        return 0;
    } else {
        r = div(m, modulo[t1]);
        if (r == 0) r = modulo[t1];
        while(--r){
            ans *= t1;
            ans %= 10;
        }
        cout << ans << endl;
    }
}
0