結果
| 問題 |
No.167 N^M mod 10
|
| コンテスト | |
| ユーザー |
cureskol
|
| 提出日時 | 2020-04-10 05:17:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 1,000 ms |
| コード長 | 456 bytes |
| コンパイル時間 | 1,802 ms |
| コンパイル使用メモリ | 166,800 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-14 09:52:49 |
| 合計ジャッジ時間 | 2,457 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int MOD=10;
int pw(int n,int k){
assert(k>=0);
int res=1;
while(k){
if(k&1)(res*=n)%=MOD;
(n*=n)%=MOD;
k>>=1;
}
return res;
}
template<typename T>
void fin(T a){
cout<<a<<endl;
exit(0);
}
signed main(){
string n,m;cin>>n>>m;
if(m=="0")fin(1);
int N=(int)(n.back()-'0'),M=(int)(m.back()-'0');
if(m.size()>=2)M+=10*(int)(m[m.size()-2]-'0');
cout<<pw(N,M+100)<<endl;
}
cureskol