結果

問題 No.167 N^M mod 10
ユーザー kapokapo
提出日時 2016-05-21 12:11:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 904 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 57,536 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 00:05:19
合計ジャッジ時間 1,339 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int calc(std::string, std::string)’:
main.cpp:58:1: warning: control reaches end of non-void function [-Wreturn-type]
   58 | }
      | ^

ソースコード

diff #

#include <iostream>
#include <string>

using namespace std;

/*

0 0
1 1
2 4 8 6 2
3 9 7 1 3
4 6 4 
5 5
6 6
7 9 3 1 7
8 4 2 6 8
9 1 9

*/

int calc(string s1, string s2)
{
	int n, m;
	char c;

	c = s1[s1.size()-1];
	n = (int)c % 48;

	c = s2[s2.size() - 1];
	m = (int)c % 48;
	if(m == 0 && s2.size() == 1) return 1;

	if(s2.size() >= 2) {
		c = s2[s2.size() - 2];
		if ((int)c % 48 == 0 && m == 0) m = 100;
		else m += ((int)c % 48) * 10;
	}

	if(n == 0 || n == 1 || n == 5 || n == 6) return n;

	int c4[2] = {6,4};
	if(n == 4) return c4[m%2];

	int c9[2] = {1,9};
	if(n == 9) return c9[m%2];

	int c2[4] = {6,2,4,8};
	if(n == 2) return c2[m%4];

	int c3[4] = {1,3,9,7};
	if(n == 3) return c3[m%4];

	int c7[4] = {1,7,9,3};
	if(n == 7) return c7[m%4];

	int c8[4] = {6,8,4,2};
	if(n == 8) return c8[m%4];
}

int main(void)
{
	string s1, s2;
	cin >> s1 >> s2;

	cout << calc(s1,s2) << endl;

	return 0;
}
0