結果
| 問題 |
No.167 N^M mod 10
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-21 18:26:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 377 bytes |
| コンパイル時間 | 1,910 ms |
| コンパイル使用メモリ | 194,208 KB |
| 最終ジャッジ日時 | 2025-01-11 09:01:42 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 27 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0),ios::sync_with_stdio(false);
string n,m; cin>>n>>m;
int rem;
if(m.size()>2)rem=*(m.end()-2)*10+*(m.end()-1)-'0'*11;
else{
rem=stoi(m);
if(rem==0){
cout<<1<<"\n"s;
return 0;
}
}
rem%=4; rem+=3;
int ans=n.back()-'0';
for(int i=0,base=ans;i<rem;++i){
ans*=base;
}
cout<<ans%10<<"\n"s;
}