結果
問題 | No.2211 Frequency Table of GCD |
ユーザー | tenten |
提出日時 | 2023-03-30 12:45:33 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 794 ms / 2,000 ms |
コード長 | 2,537 bytes |
コンパイル時間 | 3,568 ms |
コンパイル使用メモリ | 89,628 KB |
実行使用メモリ | 76,684 KB |
最終ジャッジ日時 | 2023-10-21 23:29:49 |
合計ジャッジ時間 | 19,826 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge9 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 95 ms
57,416 KB |
testcase_01 | AC | 103 ms
57,512 KB |
testcase_02 | AC | 96 ms
57,264 KB |
testcase_03 | AC | 269 ms
58,700 KB |
testcase_04 | AC | 509 ms
64,288 KB |
testcase_05 | AC | 580 ms
66,976 KB |
testcase_06 | AC | 523 ms
64,248 KB |
testcase_07 | AC | 641 ms
66,920 KB |
testcase_08 | AC | 215 ms
59,056 KB |
testcase_09 | AC | 217 ms
59,412 KB |
testcase_10 | AC | 271 ms
59,448 KB |
testcase_11 | AC | 256 ms
59,280 KB |
testcase_12 | AC | 282 ms
58,744 KB |
testcase_13 | AC | 472 ms
64,140 KB |
testcase_14 | AC | 507 ms
64,216 KB |
testcase_15 | AC | 500 ms
62,824 KB |
testcase_16 | AC | 491 ms
64,112 KB |
testcase_17 | AC | 580 ms
66,952 KB |
testcase_18 | AC | 724 ms
70,168 KB |
testcase_19 | AC | 794 ms
73,848 KB |
testcase_20 | AC | 687 ms
70,812 KB |
testcase_21 | AC | 676 ms
70,164 KB |
testcase_22 | AC | 697 ms
70,044 KB |
testcase_23 | AC | 215 ms
59,620 KB |
testcase_24 | AC | 496 ms
63,956 KB |
testcase_25 | AC | 267 ms
59,272 KB |
testcase_26 | AC | 84 ms
56,704 KB |
testcase_27 | AC | 671 ms
76,684 KB |
testcase_28 | AC | 485 ms
63,540 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 m = sc.nextInt(); HashMap<Integer, Integer> counts = new HashMap<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); counts.put(x, counts.getOrDefault(x, 0) + 1); } long[] dp = new long[m + 1]; for (int i = m; i >= 1; i--) { int tmp = 0; for (int j = 1; j * i <= 200001; j++) { tmp += counts.getOrDefault(j * i, 0); } dp[i] = (pow(2, tmp) - 1 + MOD) % MOD; for (int j = 2; j * i <= m; j++) { dp[i] += MOD - dp[j * i]; dp[i] %= MOD; } } StringBuilder sb = new StringBuilder(); for (int i = 1; i <= m; i++) { sb.append(dp[i]).append("\n"); } System.out.print(sb); } 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(); } }