結果

問題 No.167 N^M mod 10
ユーザー masa
提出日時 2015-03-20 00:10:26
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 603 bytes
コンパイル時間 513 ms
コンパイル使用メモリ 64,628 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-28 23:30:51
合計ジャッジ時間 1,441 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>

using namespace std;

int main() {
	string str_n, str_m;

	cin >> str_n >> str_m;
	int base = str_n[str_n.size() - 1] - '0';

	if (str_m == "0") {
		cout << 1 << endl;
		return 0;
	}

	int tmp = base;
	int count = 1;
	while(1) {
		tmp = (tmp * base) % 10;
		count++;
		if (tmp == base) {
			break;
		}
	}

	int multiple = str_m[str_m.size() - 1] - '0';
	if (multiple == 0) { multiple = 1; }

	int ans = (int) pow(base, multiple) % 10;
	cout << ans << endl;

	return 0;
}
0