結果

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

ソースコード

diff #

#include <iostream>

using namespace std;

int main()
{
	long long 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