結果
問題 | No.1791 Repeat Multiplication |
ユーザー | tenten |
提出日時 | 2023-01-17 09:34:51 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 626 ms / 3,000 ms |
コード長 | 2,271 bytes |
コンパイル時間 | 3,214 ms |
コンパイル使用メモリ | 92,388 KB |
実行使用メモリ | 86,656 KB |
最終ジャッジ日時 | 2024-06-10 14:05:36 |
合計ジャッジ時間 | 18,988 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
50,316 KB |
testcase_01 | AC | 55 ms
50,400 KB |
testcase_02 | AC | 57 ms
50,288 KB |
testcase_03 | AC | 56 ms
50,252 KB |
testcase_04 | AC | 58 ms
50,356 KB |
testcase_05 | AC | 61 ms
50,392 KB |
testcase_06 | AC | 56 ms
50,312 KB |
testcase_07 | AC | 57 ms
50,208 KB |
testcase_08 | AC | 266 ms
56,672 KB |
testcase_09 | AC | 253 ms
57,468 KB |
testcase_10 | AC | 249 ms
55,864 KB |
testcase_11 | AC | 244 ms
56,616 KB |
testcase_12 | AC | 214 ms
58,724 KB |
testcase_13 | AC | 554 ms
84,524 KB |
testcase_14 | AC | 594 ms
86,656 KB |
testcase_15 | AC | 441 ms
78,596 KB |
testcase_16 | AC | 438 ms
74,448 KB |
testcase_17 | AC | 544 ms
86,596 KB |
testcase_18 | AC | 503 ms
80,564 KB |
testcase_19 | AC | 539 ms
82,828 KB |
testcase_20 | AC | 471 ms
76,988 KB |
testcase_21 | AC | 549 ms
82,752 KB |
testcase_22 | AC | 626 ms
86,596 KB |
testcase_23 | AC | 474 ms
78,564 KB |
testcase_24 | AC | 528 ms
84,544 KB |
testcase_25 | AC | 502 ms
82,628 KB |
testcase_26 | AC | 579 ms
86,564 KB |
testcase_27 | AC | 473 ms
80,556 KB |
testcase_28 | AC | 591 ms
86,600 KB |
testcase_29 | AC | 576 ms
86,444 KB |
testcase_30 | AC | 576 ms
86,548 KB |
testcase_31 | AC | 53 ms
50,372 KB |
testcase_32 | AC | 621 ms
86,612 KB |
testcase_33 | AC | 567 ms
86,424 KB |
testcase_34 | AC | 569 ms
86,520 KB |
ソースコード
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(); } }