結果
問題 | No.167 N^M mod 10 |
ユーザー |
![]() |
提出日時 | 2015-10-14 09:58:41 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 474 bytes |
コンパイル時間 | 1,318 ms |
コンパイル使用メモリ | 58,920 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 01:22:26 |
合計ジャッジ時間 | 1,455 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#include <iostream> #include <algorithm> #include <stdlib.h> #include <string> using namespace std; int pow(int m,int n){ if (n==0) n=4; int k=m; for(int i=0;i<n-1;i++){ k=(k*m)%10; } return k; } int main() { string s,t; cin>>s>>t; int m=atoi(s.substr(s.length()-1,1).c_str()); int l=t.length(); if(l<2){ if(t!="0"){ cout<<pow(m,atoi(t.substr(0,1).c_str()))<<endl; } else cout<<1<<endl; } else{ cout<<pow(m,atoi(t.substr(l-2,2).c_str())%4)<<endl; } return 0; }