結果

問題 No.167 N^M mod 10
ユーザー cureskol
提出日時 2020-04-10 05:12:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 384 bytes
コンパイル時間 1,840 ms
コンパイル使用メモリ 167,960 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-14 09:42:22
合計ジャッジ時間 2,651 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 8 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#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');
  M+=3;
  cout<<(pw(N,M+3)*N)%MOD<<endl;
}
0