結果
| 問題 |
No.167 N^M mod 10
|
| コンテスト | |
| ユーザー |
cureskol
|
| 提出日時 | 2020-04-10 05:13:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 376 bytes |
| コンパイル時間 | 1,830 ms |
| コンパイル使用メモリ | 166,488 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-14 09:44:59 |
| 合計ジャッジ時間 | 2,513 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 WA * 2 |
ソースコード
#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;
}
signed main(){
string n,m;cin>>n>>m;
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+3)*N)%MOD<<endl;
}
cureskol