結果
問題 | No.167 N^M mod 10 |
ユーザー |
![]() |
提出日時 | 2016-05-04 16:14:06 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 2,055 bytes |
コンパイル時間 | 645 ms |
コンパイル使用メモリ | 83,524 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 01:30:55 |
合計ジャッジ時間 | 1,642 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#include <algorithm> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath> #include <iostream> #include <queue> #include <list> #include <stack> #include <map> #include <numeric> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; ll mod(const string& n, const ll& m){ ll ret = 0; int j = 0; while(true){ if(ret >= m) ret%=m; if(j >= n.size()) break; ret = ret*10 + (n[j]-'0'); j++; } return ret; } int main(){ string N, M; cin >> N >> M; ll n = N[N.length()-1]-'0'; if(M.length()==1 && M[0] == '0'){ cout << 1 << endl; } else if(n == 0){ cout << 0 << endl; } else if(n == 1){ cout << 1 << endl; } else if(n == 2){ int res = mod(M, 4); if(res == 0) cout << 6 << endl; if(res == 1) cout << 2 << endl; if(res == 2) cout << 4 << endl; if(res == 3) cout << 8 << endl; } else if(n == 3){ int res = mod(M, 4); if(res == 0) cout << 1 << endl; if(res == 1) cout << 3 << endl; if(res == 2) cout << 9 << endl; if(res == 3) cout << 7 << endl; } else if(n == 4){ int res = mod(M, 2); if(res == 0) cout << 6 << endl; if(res == 1) cout << 4 << endl; } else if(n == 5){ cout << 5 << endl; } else if(n == 6){ cout << 6 << endl; } else if(n == 7){ int res = mod(M, 4); if(res == 0) cout << 1 << endl; if(res == 1) cout << 7 << endl; if(res == 2) cout << 9 << endl; if(res == 3) cout << 3 << endl; } else if(n == 8){ int res = mod(M, 4); if(res == 0) cout << 6 << endl; if(res == 1) cout << 8 << endl; if(res == 2) cout << 4 << endl; if(res == 3) cout << 2 << endl; } else if(n == 9){ int res = mod(M, 2); if(res == 0) cout << 1 << endl; if(res == 1) cout << 9 << endl; } return 0; }