結果
| 問題 |
No.167 N^M mod 10
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-04-22 21:21:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,143 bytes |
| コンパイル時間 | 642 ms |
| コンパイル使用メモリ | 63,612 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-22 01:30:37 |
| 合計ジャッジ時間 | 1,491 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 27 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
string n, m;
cin >> n >> m;
int nn = *(--n.end()) - '0';
int mn;
if (m.size() == 1) {
if (m.at(0) == '0') {
cout << "1" << endl;
return 0;
}
mn = *(--m.end()) - '0';
} else {
mn = *(--m.end()) - '0' + 10 * (*(m.end() -2) - '0');
}
vector<vector<int>> hitoketame{{0,0,0,0}, {1,1,1,1}, {6,2,4,8}, {1,3,9,7}, {6,4,6,4}, {5,5,5,5}, {6,6,6,6}, {1,7,9,3}, {6,8,4,2}, {1,9,1,9}};
// mの下位一or二ケタmnと、3(2進法で11)の&をとって、
// 00ならhitoketame[?][0]、01ならhitoketame[?][1]、
// 10ならhitoketame[?][2]、11ならhitoketame[?][3]
// ?は n mod10 = nnの値
if ((mn & 3) == 0) {
cout << hitoketame[nn][0] << endl;
} else if ((mn & 3) == 1) {
cout << hitoketame[nn][1] << endl;
} else if ((mn & 3) == 2) {
cout << hitoketame[nn][2] << endl;
} else {
cout << hitoketame[nn][3] << endl;
}
return 0;
}