結果

問題 No.251 大きな桁の復習問題(1)
ユーザー bal4ubal4u
提出日時 2019-04-14 13:55:38
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,614 bytes
コンパイル時間 691 ms
コンパイル使用メモリ 30,920 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 02:56:09
合計ジャッジ時間 1,116 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 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 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'ins':
main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:16:17: note: in expansion of macro 'gc'
   16 |         do *s = gc();
      |                 ^~
main.c: At top level:
main.c:23:18: warning: built-in function 'pow' declared as non-function [-Wbuiltin-declaration-mismatch]
   23 | int base[12000], pow[12000];
      |                  ^~~

ソースコード

diff #

// yukicoder: No.251 大きな桁の復習問題(1)
// 2019.4.14 bal4u

#include <stdio.h>

#if 1
#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 base[12000], pow[12000];

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

	if (*str == '0') { *num = 0; return; }
	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;
}

#define MOD 129402307

char s[100005];

int bigPow(int x, int p)
{
	int r = 1;
	while (p) {
		if (p & 1) r = (long long)r * x % MOD;
		x = (long long)x * x % MOD;
		p >>= 1;
	}
	return r;
}

int main()
{
	int w, b, p;

	// Nの入力と処理
	w = ins(s);
	mpStr2Num(base, w, s);
	if (base[0] == 0) {	puts("0"); return 0; }
	if (base[0] == 1 && base[1] == 1) { puts("1"); return 0; }

	// Mの入力と処理
	w = ins(s);
	mpStr2Num(pow, w, s);
	if (pow[0] == 0) { puts("1"); return 0; }

	if ((b = mpMod(base, MOD)) == 0) { puts("0"); return 0; }
	p = mpMod(pow, MOD-1);

	printf("%d\n", bigPow(b, p));
	return 0;
}
0