結果

問題 No.167 N^M mod 10
ユーザー itezpace
提出日時 2016-09-17 11:21:01
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 534 bytes
コンパイル時間 1,540 ms
コンパイル使用メモリ 55,548 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-17 08:13:08
合計ジャッジ時間 2,796 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
const int mod=10;

int ary[9][4]={
  {1,1,1,1},
  {2,4,8,6},
  {3,9,7,1},
  {4,6,4,6},
  {5,5,5,5},
  {6,6,6,6},
  {7,9,3,1},
  {8,4,2,6},
  {9,1,9,1}
};

int main(){
  string n,m;
  cin>>n;
  cin>>m;
  int a=n[n.size()-1]-'0';
  int c=0, d=0;
  for(int i=0; i<m.size(); ++i){
    int b=m[i]-'0';
    if(c+b<10){
      c+=b;
    } else {
      c+=b;
      c-=10;
      d+=1;
    }
  }
  int e=c%4;
  int f=d%4;
  int g=e+f;
  g%=mod;
  if(g==3) g=-1;
  cout<<ary[a-1][g+1]<<endl;
  return 0;
}
0