結果

問題 No.167 N^M mod 10
ユーザー bal4ubal4u
提出日時 2019-04-12 22:47:02
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,327 bytes
コンパイル時間 1,021 ms
コンパイル使用メモリ 30,148 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 00:28:47
合計ジャッジ時間 1,876 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 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 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.169 何分かかるの
// 2019.4.12 bal4u

#include <stdio.h>

#if 0
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int ins(char *s)  // 文字列の入力 スペース以下の文字で入力終了
{
	char *p = s;
	do *s = gc();
	while (*s++ > ' ');
	*--s = 0;
	return s - p;
}

#define N       1000000000
int num[1200]; int w;

void mpStr2Num(int *num, int w, char *str)
{
	char *ss;
	int  *nn;
	int  k, x;

	ss = str + w;
	x = 0, k = 1, nn = num;
	do {
		x += (*--ss - '0') * k;
		k *= 10;
		if (k == N || ss == str) *++nn = x, x = 0, k = 1;
	} while (ss != str);
	*num = nn - num;
}

// 多倍長整数 za を 整数 ab で割ったあまり  = za % zb
int mpMod(int *za, int zb)
{
	int  i = *za;
	int  *aa = za + *za;
	int  ca = 0;
	long long x;

	while (i--) {
		x = (long long)N * ca + *aa--;
		ca = (int)(x % zb);
	}
	return ca;
}

int tbl[10][4] = { {0,0,0,0},{1,1,1,1},{6,2,4,8},{1,3,9,7},{6,4,6,4},
{5,5,5,5},{6,6,6,6},{1,7,9,3},{6,8,4,2},{1,9,1,9} };

char n[10005];

int main()
{
	int base, r;

	w = ins(n);
	base = n[w - 1] & 0xf;
	w = ins(n);
	if (n[0] == '0') { puts("1"); return 0; }
	if (base == 0) { puts("0"); return 0; }
	mpStr2Num(num, w, n);
	r = mpMod(num, 4);
	printf("%d\n", tbl[base][r]);
	return 0;
}
0