結果

問題 No.167 N^M mod 10
ユーザー 👑 CleyL
提出日時 2020-01-10 00:07:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 443 bytes
コンパイル時間 492 ms
コンパイル使用メモリ 64,512 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-23 05:07:43
合計ジャッジ時間 1,370 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
int main(){
    string n,m;cin>>n>>m;
    if(m == "0"){
        cout << 1 << endl;
        return 0;
    }
    int N = n[n.size()-1]-'0';
    int M;
    if(m.size() == 1){
        M = m[0]-'0';
    }else{
        M = (m[m.size()-2]-'0')*10 + m[m.size()-1]-'0';
    }
    M %= 4;
    if(!M)M+=4;
    int ans = N;
    for(int i = 1; M > i; i++){
        ans = (N*ans)%10;
    }
    cout << ans << endl;
}
0