結果

問題 No.167 N^M mod 10
ユーザー zangezange
提出日時 2015-03-20 00:10:26
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,323 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 53,256 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 08:52:02
合計ジャッジ時間 1,595 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:60:10: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  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' + (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