結果

問題 No.167 N^M mod 10
コンテスト
ユーザー masa
提出日時 2015-03-19 23:50:05
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 637 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 502 ms
コンパイル使用メモリ 92,276 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-18 06:22:31
合計ジャッジ時間 1,216 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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 = 0;
	for (int i = 0; i < str_m.size(); i++) {
		multiple = (multiple * 10 + str_m[i] - '0') % count;
	}

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

	return 0;
}
0