結果

問題 No.1529 Constant Lcm
ユーザー 👑 ygussanyygussany
提出日時 2021-06-04 20:16:42
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 54 ms / 3,000 ms
コード長 669 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 30,592 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 23:25:07
合計ジャッジ時間 1,730 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 47 ms
5,376 KB
testcase_11 AC 19 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 41 ms
5,376 KB
testcase_14 AC 29 ms
5,376 KB
testcase_15 AC 29 ms
5,376 KB
testcase_16 AC 21 ms
5,376 KB
testcase_17 AC 13 ms
5,376 KB
testcase_18 AC 14 ms
5,376 KB
testcase_19 AC 29 ms
5,376 KB
testcase_20 AC 47 ms
5,376 KB
testcase_21 AC 48 ms
5,376 KB
testcase_22 AC 49 ms
5,376 KB
testcase_23 AC 47 ms
5,376 KB
testcase_24 AC 48 ms
5,376 KB
testcase_25 AC 54 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int Mod = 998244353;

long long pow_mod(int n, int k)
{
	long long N, ans = 1;
	for (N = n; k > 0; k >>= 1, N = N * N % Mod) if (k & 1) ans = ans * N % Mod;
	return ans;
}

int main()
{
	int N;
	scanf("%d", &N);
	
	char flag[1000001] = {};
	int i, j, k, x, max;
	long long ans = 1;
	for (i = 2; i < N; i++) {
		if (flag[i] != 0) continue;
		for (j = i * 2; j < N; j += i) flag[j] = 1;
		
		for (k = i, max = 0; k < N; k += i) {
			for (x = k, j = 0; x % i == 0; x /= i, j++);
			for (x = N - k; x % i == 0; x /= i, j++);
			if (max < j) max = j;
		}
		ans = ans * pow_mod(i, max) % Mod;
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}
0