結果

問題 No.1529 Constant Lcm
ユーザー 👑 ygussanyygussany
提出日時 2021-06-04 20:16:42
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 54 ms / 3,000 ms
コード長 669 bytes
コンパイル時間 1,317 ms
コンパイル使用メモリ 29,500 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-12 08:58:56
合計ジャッジ時間 2,948 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 48 ms
4,380 KB
testcase_11 AC 18 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 40 ms
4,376 KB
testcase_14 AC 29 ms
4,376 KB
testcase_15 AC 28 ms
4,376 KB
testcase_16 AC 20 ms
4,380 KB
testcase_17 AC 12 ms
4,376 KB
testcase_18 AC 14 ms
4,376 KB
testcase_19 AC 29 ms
4,376 KB
testcase_20 AC 48 ms
4,380 KB
testcase_21 AC 47 ms
4,376 KB
testcase_22 AC 49 ms
4,376 KB
testcase_23 AC 46 ms
4,376 KB
testcase_24 AC 49 ms
4,380 KB
testcase_25 AC 54 ms
4,380 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