結果
問題 | No.1396 Giri |
ユーザー | tenten |
提出日時 | 2023-01-12 10:07:57 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 136 ms / 2,000 ms |
コード長 | 2,208 bytes |
コンパイル時間 | 2,719 ms |
コンパイル使用メモリ | 88,036 KB |
実行使用メモリ | 55,548 KB |
最終ジャッジ日時 | 2023-08-24 18:42:39 |
合計ジャッジ時間 | 5,782 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
49,500 KB |
testcase_01 | AC | 42 ms
49,700 KB |
testcase_02 | AC | 134 ms
55,228 KB |
testcase_03 | AC | 42 ms
49,408 KB |
testcase_04 | AC | 41 ms
49,956 KB |
testcase_05 | AC | 135 ms
55,472 KB |
testcase_06 | AC | 42 ms
49,492 KB |
testcase_07 | AC | 41 ms
49,956 KB |
testcase_08 | AC | 41 ms
49,408 KB |
testcase_09 | AC | 42 ms
49,476 KB |
testcase_10 | AC | 43 ms
49,456 KB |
testcase_11 | AC | 42 ms
49,492 KB |
testcase_12 | AC | 43 ms
49,776 KB |
testcase_13 | AC | 42 ms
49,504 KB |
testcase_14 | AC | 42 ms
49,492 KB |
testcase_15 | AC | 42 ms
49,524 KB |
testcase_16 | AC | 43 ms
49,516 KB |
testcase_17 | AC | 46 ms
49,568 KB |
testcase_18 | AC | 58 ms
50,648 KB |
testcase_19 | AC | 92 ms
53,368 KB |
testcase_20 | AC | 109 ms
53,216 KB |
testcase_21 | AC | 127 ms
53,152 KB |
testcase_22 | AC | 134 ms
55,188 KB |
testcase_23 | AC | 134 ms
55,548 KB |
testcase_24 | AC | 136 ms
55,508 KB |
testcase_25 | AC | 136 ms
55,344 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static final int MOD = 998244353; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] nums = new int[n + 1]; for (int i = 1; i <= n; i++) { nums[i] = i; } int max = 0; long ans = 1; for (int i = 2; i <= n; i++) { ans *= nums[i]; ans %= MOD; max = Math.max(max, nums[i]); for (int j = 2; j * i <= n; j++) { nums[j * i] /= nums[i]; } } ans *= pow(max, MOD - 2); ans %= MOD; System.out.println(ans); } static long pow(long x, int p) { if (p == 0) { return 1; } else if (p % 2 == 0) { return pow(x * x % MOD, p / 2); } else { return pow(x, p - 1) * x % MOD; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }