結果

問題 No.1791 Repeat Multiplication
ユーザー tentententen
提出日時 2021-12-21 08:18:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 452 ms / 3,000 ms
コード長 1,615 bytes
コンパイル時間 3,718 ms
コンパイル使用メモリ 74,268 KB
実行使用メモリ 96,472 KB
最終ジャッジ日時 2023-10-13 19:47:18
合計ジャッジ時間 16,220 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,340 KB
testcase_01 AC 44 ms
49,212 KB
testcase_02 AC 44 ms
49,236 KB
testcase_03 AC 46 ms
49,308 KB
testcase_04 AC 49 ms
49,404 KB
testcase_05 AC 51 ms
49,260 KB
testcase_06 AC 47 ms
49,240 KB
testcase_07 AC 49 ms
49,356 KB
testcase_08 AC 233 ms
55,448 KB
testcase_09 AC 222 ms
55,396 KB
testcase_10 AC 224 ms
57,692 KB
testcase_11 AC 238 ms
55,848 KB
testcase_12 AC 174 ms
55,140 KB
testcase_13 AC 421 ms
91,332 KB
testcase_14 AC 411 ms
92,080 KB
testcase_15 AC 361 ms
82,240 KB
testcase_16 AC 352 ms
68,436 KB
testcase_17 AC 411 ms
93,208 KB
testcase_18 AC 382 ms
86,236 KB
testcase_19 AC 417 ms
89,492 KB
testcase_20 AC 369 ms
83,388 KB
testcase_21 AC 408 ms
90,540 KB
testcase_22 AC 425 ms
93,372 KB
testcase_23 AC 362 ms
84,388 KB
testcase_24 AC 409 ms
92,068 KB
testcase_25 AC 395 ms
88,632 KB
testcase_26 AC 416 ms
92,248 KB
testcase_27 AC 372 ms
87,848 KB
testcase_28 AC 421 ms
96,264 KB
testcase_29 AC 421 ms
96,284 KB
testcase_30 AC 420 ms
95,992 KB
testcase_31 AC 44 ms
49,416 KB
testcase_32 AC 410 ms
96,112 KB
testcase_33 AC 426 ms
95,996 KB
testcase_34 AC 452 ms
96,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] lefts = new int[n + 1];
        Arrays.fill(lefts, 1);
        for (int i = 2; i <= n; i++) {
            for (int j = 2; j * i <= n; j++) {
                lefts[j * i] += lefts[i];
            }
        }
        long[] rights = new long[n + 1];
        long[] ans = 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];
            }
            ans[i] = lefts[i] * rights[i];
        }
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            sb.append(ans[sc.nextInt()]).append("\n");
        }
        System.out.print(sb);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0