結果

問題 No.1529 Constant Lcm
ユーザー bal4ubal4u
提出日時 2021-08-15 07:51:14
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 319 ms / 3,000 ms
コード長 1,617 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 32,256 KB
実行使用メモリ 73,216 KB
最終ジャッジ日時 2024-04-16 06:39:14
合計ジャッジ時間 4,532 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 283 ms
66,944 KB
testcase_11 AC 80 ms
27,776 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 245 ms
57,728 KB
testcase_14 AC 135 ms
38,016 KB
testcase_15 AC 142 ms
40,064 KB
testcase_16 AC 104 ms
31,488 KB
testcase_17 AC 35 ms
18,176 KB
testcase_18 AC 43 ms
19,456 KB
testcase_19 AC 135 ms
38,912 KB
testcase_20 AC 306 ms
72,960 KB
testcase_21 AC 306 ms
73,060 KB
testcase_22 AC 308 ms
73,084 KB
testcase_23 AC 307 ms
72,960 KB
testcase_24 AC 316 ms
73,088 KB
testcase_25 AC 319 ms
73,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yuki 1529 Constant Lcm
// 2021.8.15

#include <stdio.h>

typedef long long ll;
const int mod = 998244353;

#define MAX  1000005
int a[MAX];
char cn[MAX];
int f[MAX][8], p[MAX][8], hi[MAX];
ll ans = 1;

void mktbl(int ma) {
	int i, j, k, m;
	for (j = 2; j <= ma; j+=2) {
		i = j, k = 0; while (!(i & 1)) k++, i >>= 1;
		f[j][hi[j]] = 2, p[j][hi[j]++] = k;
	}
	for (m = 3; m <= ma; m += 2) if (!cn[m]) {
		f[m][hi[m]] = m, p[m][hi[m]++] = 1;
		for (j = m << 1; j <= ma; j += m) {
			cn[j] = 1;
			i = j, k = 0; while (i % m == 0) i /= m, k++;
			f[j][hi[j]] = m, p[j][hi[j]++] = k;
		}
	}
  }

int pow_mod(int x, int p) {
	int r = 1; while (p) {
		if (p & 1) r = (ll)r * x % mod;
		x = (ll)x * x % mod;
		p >>= 1;
	}
	return r;
}

inline static void mul_pow(int a) { ans = ans * a % mod; }
inline static void chmax(int *a, int b) { if (*a < b) *a = b; }

void reg(int x, int y) {
	int i = 0, j = 0;
	while (i < hi[x] && j < hi[y]) {
		if (f[x][i] < f[y][j]) chmax(a+f[x][i], p[x][i]), ++i;
		else if (f[x][i] > f[y][j]) chmax(a+f[y][j], p[y][j]), ++j;
		else chmax(a+f[x][i], p[x][i]+p[y][j]), ++i, ++j;
	}
	while (i < hi[x]) chmax(a+f[x][i], p[x][i]), ++i;
	while (j < hi[y]) chmax(a+f[y][j], p[y][j]), ++j;
}

int main()
{
	int N, i, j;

	scanf("%d", &N);
	mktbl(N-1);
/*
for (i = 2; i <= 40; ++i) {
	printf("[%d] sz=%d: ", i, hi[i]);
	for (j = 0; j < hi[i]; ++j) printf("(%d,%d) ", f[i][j],p[i][j]);
	printf("\n");
}
*/
	for (i = 1, j = N-1; i <= j; ++i, --j) reg(i, j);
	if (a[2]) mul_pow(pow_mod(2, a[2]));
	for (i = 3; i < N; i+=2) if (a[i])
		mul_pow(pow_mod(i, a[i]));
	printf("%d\n", (int)ans);
	return 0;
}
0