結果
問題 | No.1529 Constant Lcm |
ユーザー |
👑 |
提出日時 | 2021-06-04 20:16:42 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 54 ms / 3,000 ms |
コード長 | 669 bytes |
コンパイル時間 | 1,061 ms |
コンパイル使用メモリ | 30,080 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-19 08:23:38 |
合計ジャッジ時間 | 1,542 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 |
ソースコード
#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;}