結果

問題 No.167 N^M mod 10
ユーザー zange
提出日時 2015-03-20 00:12:49
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,363 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 56,044 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-28 23:31:53
合計ジャッジ時間 1,330 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 24 WA * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:63:17: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |         cout << ans << endl;
      |                 ^~~

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

string N;
string M;

int sumFigure(int size) {
	int sum = 0;
	for (int i = 0; i < size; i++) {
		sum += M[i] - '0';
	}
	return sum;
}

int main() {
	int ans;
	cin >> N >> M;

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

	int digit = N[N.size() - 1] - '0';
	int sizeM = M.size();
	int sum = sumFigure(sizeM);
	int lastTwoDigit = (M[sizeM - 1] - '0');
	if (sizeM > 1) {
		lastTwoDigit += (M[sizeM - 2] - '0') * 10;
	}

	if (digit == 0 || digit == 1 || digit == 5 || digit == 6) ans = digit;
	else if (digit == 4 || digit == 9) {
		if (sum % 2 == 0) {
			if (digit == 4) ans = 6;
			else ans = 1;
		} else {
			ans = digit;
		}
	}
	else if (digit == 2 || digit == 3 || digit == 7 || digit == 8 || digit == 9) {
		if (lastTwoDigit % 4 == 0) {
			if (digit == 2) ans = 6;
			else if (digit == 3) ans = 1;
			else if (digit == 7) ans = 1;
			else if (digit == 8) ans = 6;
		} else if (lastTwoDigit % 4 == 1) {
			ans = digit;
		} else if (lastTwoDigit % 4 == 2) {
			if (digit == 2) ans = 4;
			else if (digit == 3) ans = 9;
			else if (digit == 7) ans = 9;
			else if (digit == 8) ans = 4;
		} else if (lastTwoDigit % 4 == 3) {
			if (digit == 2) ans = 8;
			else if (digit == 3) ans = 7;
			else if (digit == 7) ans = 3;
			else if (digit == 8) ans = 2;
		}
	}

	cout << ans << endl;

	return 0;
}
0