結果

問題 No.167 N^M mod 10
ユーザー data9824
提出日時 2015-05-24 21:07:31
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 535 bytes
コンパイル時間 597 ms
コンパイル使用メモリ 59,372 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-06 08:06:56
合計ジャッジ時間 1,247 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19 WA * 8
権限があれば一括ダウンロードができます

ソースコード

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