結果

問題 No.167 N^M mod 10
ユーザー data9824data9824
提出日時 2015-05-24 21:07:31
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 535 bytes
コンパイル時間 430 ms
コンパイル使用メモリ 60,552 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 12:48:47
合計ジャッジ時間 1,726 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	string n, m;
	cin >> n >> m;
	if (count(m.begin(), m.end(), '0') == m.size()) {
		cout << 1 << endl;
		return 0;
	}
	static int lsd[10][4]; // [n][m]
	for (int n = 0; n < 10; ++n) {
		lsd[n][0] = 1;
		for (int m = 1; m < 4; ++m) {
			lsd[n][m % 4] = lsd[n][m - 1] * n % 10;
		}
	}
	int ls2dM = (m.size() >= 2 ? (m[m.size() - 2] - '0') : 0) * 10 
		+ (m[m.size() - 1] - '0');
	cout << lsd[(n.back() - '0')][ls2dM % 4] << endl;
	return 0;
}
0