結果

問題 No.167 N^M mod 10
ユーザー CrepsuculeRain
提出日時 2016-05-30 23:58:45
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 385 bytes
コンパイル時間 545 ms
コンパイル使用メモリ 54,928 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-07 19:44:19
合計ジャッジ時間 1,544 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	int p = N % 10;
	if (M == 0) {
		cout << 1;
		return 0;
	}
	int t = M;
	int k = p;
	int i = 0;
	do {
		k = (k * p) % 10;
		i++;
	} while (!(k == p));
	t = M % i - 1 + i;
	for (int i = 0; i < t; i++) {
		int x = N % 10;
		p *= x;
		p = p % 10;
	}
	cout << p;

	

	getchar();
	getchar();
	return 0;
}


0