結果

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

テストケース

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

ソースコード

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 (modulo[t1] == 1) {
        cout << n[n.size()-1] << endl;
        return 0;
    } else {
        r = div(m, modulo[t1]);
        while(--r){
            ans *= t1;
            ans %= 10;
        }
        cout << ans << endl;
    }
}
0