結果

問題 No.1791 Repeat Multiplication
ユーザー tentententen
提出日時 2023-04-18 12:26:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 798 ms / 3,000 ms
コード長 2,116 bytes
コンパイル時間 2,240 ms
コンパイル使用メモリ 91,560 KB
実行使用メモリ 75,012 KB
最終ジャッジ日時 2024-04-21 12:24:06
合計ジャッジ時間 15,825 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
36,860 KB
testcase_01 AC 47 ms
36,940 KB
testcase_02 AC 50 ms
36,780 KB
testcase_03 AC 50 ms
37,216 KB
testcase_04 AC 51 ms
36,804 KB
testcase_05 AC 52 ms
37,168 KB
testcase_06 AC 47 ms
36,988 KB
testcase_07 AC 48 ms
37,192 KB
testcase_08 AC 319 ms
48,164 KB
testcase_09 AC 290 ms
47,280 KB
testcase_10 AC 213 ms
47,204 KB
testcase_11 AC 209 ms
46,964 KB
testcase_12 AC 179 ms
44,428 KB
testcase_13 AC 395 ms
72,400 KB
testcase_14 AC 408 ms
73,056 KB
testcase_15 AC 361 ms
65,060 KB
testcase_16 AC 345 ms
64,464 KB
testcase_17 AC 426 ms
74,024 KB
testcase_18 AC 382 ms
68,684 KB
testcase_19 AC 408 ms
72,140 KB
testcase_20 AC 351 ms
66,192 KB
testcase_21 AC 410 ms
71,736 KB
testcase_22 AC 411 ms
74,168 KB
testcase_23 AC 370 ms
67,208 KB
testcase_24 AC 407 ms
73,012 KB
testcase_25 AC 390 ms
70,864 KB
testcase_26 AC 420 ms
73,312 KB
testcase_27 AC 426 ms
68,600 KB
testcase_28 AC 798 ms
74,580 KB
testcase_29 AC 477 ms
74,520 KB
testcase_30 AC 416 ms
74,668 KB
testcase_31 AC 47 ms
36,812 KB
testcase_32 AC 427 ms
75,012 KB
testcase_33 AC 426 ms
74,692 KB
testcase_34 AC 434 ms
74,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long[] lefts = new long[n + 1];
        lefts[1] = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = 2; j * i <= n; j++) {
                lefts[j * i] += lefts[i];
            }
        }
        long[] rights = new long[n + 1];
        for (int i = n; i >= 1; i--) {
            rights[i] = 1;
            for (int j = 2; j * i <= n; j++) {
                rights[i] += rights[j * i];
            }
        }
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        while (q-- > 0) {
            int x = sc.nextInt();
            sb.append(lefts[x] * rights[x]).append("\n");
        }
        System.out.print(sb);
    }
}
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