結果

問題 No.1791 Repeat Multiplication
ユーザー tentententen
提出日時 2023-01-17 09:34:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 707 ms / 3,000 ms
コード長 2,271 bytes
コンパイル時間 6,760 ms
コンパイル使用メモリ 86,576 KB
実行使用メモリ 87,368 KB
最終ジャッジ日時 2023-08-30 14:07:17
合計ジャッジ時間 20,875 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,408 KB
testcase_01 AC 45 ms
49,280 KB
testcase_02 AC 46 ms
49,388 KB
testcase_03 AC 46 ms
49,580 KB
testcase_04 AC 48 ms
49,560 KB
testcase_05 AC 50 ms
49,356 KB
testcase_06 AC 46 ms
49,504 KB
testcase_07 AC 48 ms
49,768 KB
testcase_08 AC 238 ms
57,768 KB
testcase_09 AC 221 ms
55,968 KB
testcase_10 AC 226 ms
56,188 KB
testcase_11 AC 216 ms
57,772 KB
testcase_12 AC 277 ms
60,292 KB
testcase_13 AC 562 ms
84,756 KB
testcase_14 AC 574 ms
84,856 KB
testcase_15 AC 452 ms
77,416 KB
testcase_16 AC 457 ms
75,184 KB
testcase_17 AC 657 ms
87,068 KB
testcase_18 AC 517 ms
81,316 KB
testcase_19 AC 602 ms
83,156 KB
testcase_20 AC 493 ms
78,088 KB
testcase_21 AC 589 ms
83,116 KB
testcase_22 AC 703 ms
86,852 KB
testcase_23 AC 531 ms
78,928 KB
testcase_24 AC 703 ms
84,820 KB
testcase_25 AC 607 ms
83,440 KB
testcase_26 AC 707 ms
87,368 KB
testcase_27 AC 542 ms
81,476 KB
testcase_28 AC 698 ms
86,976 KB
testcase_29 AC 655 ms
87,148 KB
testcase_30 AC 653 ms
87,040 KB
testcase_31 AC 44 ms
49,632 KB
testcase_32 AC 678 ms
87,028 KB
testcase_33 AC 669 ms
87,132 KB
testcase_34 AC 653 ms
86,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static long[] counts;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int q = sc.nextInt();
        counts = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            dfw(i);
        }
        long[] times = new long[n + 1];
        times[1] = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = 2; j * i <= n; j++) {
                times[j * i] += times[i];
            }
            counts[i] *= times[i];
        }
        StringBuilder sb = new StringBuilder();
        while (q-- > 0) {
            sb.append(counts[sc.nextInt()]).append("\n");
        }
        System.out.print(sb);
    }
    
    static long dfw(int x) {
        if (counts[x] == 0) {
            counts[x] = 1;
            for (int i = 2; i * x < counts.length; i++) {
                counts[x] += dfw(x * i);
            }
        }
        return counts[x];
    }
}

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();
    }
    
}
0