結果
問題 | No.1514 Squared Matching |
ユーザー | tenten |
提出日時 | 2023-06-22 17:49:55 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 3,185 ms / 4,000 ms |
コード長 | 2,549 bytes |
コンパイル時間 | 2,583 ms |
コンパイル使用メモリ | 91,820 KB |
実行使用メモリ | 252,196 KB |
最終ジャッジ日時 | 2024-06-30 00:40:25 |
合計ジャッジ時間 | 53,411 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
36,976 KB |
testcase_01 | AC | 2,924 ms
251,940 KB |
testcase_02 | AC | 44 ms
36,972 KB |
testcase_03 | AC | 44 ms
36,640 KB |
testcase_04 | AC | 42 ms
36,992 KB |
testcase_05 | AC | 55 ms
37,264 KB |
testcase_06 | AC | 180 ms
45,876 KB |
testcase_07 | AC | 579 ms
81,356 KB |
testcase_08 | AC | 2,661 ms
242,060 KB |
testcase_09 | AC | 2,316 ms
209,680 KB |
testcase_10 | AC | 2,547 ms
228,164 KB |
testcase_11 | AC | 2,603 ms
238,744 KB |
testcase_12 | AC | 2,730 ms
245,676 KB |
testcase_13 | AC | 3,015 ms
249,276 KB |
testcase_14 | AC | 2,774 ms
250,972 KB |
testcase_15 | AC | 3,115 ms
251,536 KB |
testcase_16 | AC | 3,185 ms
251,884 KB |
testcase_17 | AC | 3,140 ms
252,092 KB |
testcase_18 | AC | 3,090 ms
251,996 KB |
testcase_19 | AC | 3,095 ms
252,196 KB |
testcase_20 | AC | 3,073 ms
252,180 KB |
testcase_21 | AC | 3,064 ms
251,992 KB |
testcase_22 | AC | 661 ms
83,360 KB |
testcase_23 | AC | 1,179 ms
122,604 KB |
testcase_24 | AC | 1,682 ms
161,752 KB |
testcase_25 | AC | 2,359 ms
201,456 KB |
ソースコード
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(); TreeMap<Integer, Integer> square = new TreeMap<>(); int idx = 1; int target = 1; while (target * target <= n) { square.put(target * target, idx++); target++; } int root = target - 1; int[] counts = new int[n + 1]; for (int i = 1; i <= n; i++) { counts[i] = i; } boolean[] isNotPrimes = new boolean[root + 1]; for (int i = 2; i <= root; i++) { if (!isNotPrimes[i]) { for (int j = 2; j * i <= root; j++) { isNotPrimes[j * i] = true; } long base = i * i; while (base <= n) { int x = (int)base; for (int j = 1; j * base <= n; j++) { counts[j * x] /= i * i; } base *= i * i; } } } long ans = 0; for (int i = 1; i <= n; i++) { ans += square.floorEntry(n / counts[i]).getValue(); } System.out.println(ans); } } 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(); } }