結果

問題 No.167 N^M mod 10
ユーザー 古寺いろは
提出日時 2015-03-23 07:09:01
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 396 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 55,516 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-22 01:12:22
合計ジャッジ時間 1,479 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>

using namespace std;

int getnum(char c){
	return c - '0';
}

int main() {
	string N, M;
	cin >> N >> M;
	int a = getnum(N[N.size() - 1]);
	int b = getnum(M[M.size() - 1]);
	if (M.size() != 1) b += getnum(M[M.size() - 2]) * 10;
	if (M.size() >= 3) b += 100;

	int ans = 1;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= 10;
	}
	cout << ans << endl;
}
0