結果

問題 No.167 N^M mod 10
ユーザー troro_kelp
提出日時 2018-12-21 21:56:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 862 bytes
コンパイル時間 783 ms
コンパイル使用メモリ 90,172 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-22 01:49:36
合計ジャッジ時間 1,502 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;
int main(void)
{
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    if (m == 1 && t[m - 1] == '0')
    {
        cout << 1 << endl;
        return 0;
    }

    int tmp = s[n - 1] - '0';

    int num;

    if (m == 1)
        num = t[m - 1] - '0';
    else if (m == 2)
        num = (t[m - 2] - '0') * 10 + (t[m - 1] - '0');
    else
        num = (t[m - 3] - '0') * 100 + (t[m - 2] - '0') * 10 + (t[m - 1] - '0');

    num %= 4;
    num = (num + 3) % 4;
    //cout << tmp << " " << num << endl;
    int ababa = tmp;
    for (int i = 0; i < num; ++i)
    {
        ababa = (ababa * tmp) % 10;
    }
    cout << ababa << endl;
    return 0;
}
0