結果
問題 | No.1514 Squared Matching |
ユーザー | tenten |
提出日時 | 2023-06-22 17:49:55 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 3,411 ms / 4,000 ms |
コード長 | 2,549 bytes |
コンパイル時間 | 3,289 ms |
コンパイル使用メモリ | 99,320 KB |
実行使用メモリ | 263,984 KB |
最終ジャッジ日時 | 2023-09-12 12:15:56 |
合計ジャッジ時間 | 59,800 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
49,596 KB |
testcase_01 | AC | 2,970 ms
263,076 KB |
testcase_02 | AC | 46 ms
47,752 KB |
testcase_03 | AC | 45 ms
49,416 KB |
testcase_04 | AC | 44 ms
49,452 KB |
testcase_05 | AC | 59 ms
50,972 KB |
testcase_06 | AC | 169 ms
58,500 KB |
testcase_07 | AC | 705 ms
93,684 KB |
testcase_08 | AC | 3,303 ms
253,132 KB |
testcase_09 | AC | 2,832 ms
220,748 KB |
testcase_10 | AC | 2,919 ms
240,880 KB |
testcase_11 | AC | 3,196 ms
250,140 KB |
testcase_12 | AC | 2,915 ms
256,276 KB |
testcase_13 | AC | 3,325 ms
260,316 KB |
testcase_14 | AC | 3,411 ms
262,696 KB |
testcase_15 | AC | 3,092 ms
262,348 KB |
testcase_16 | AC | 3,329 ms
263,984 KB |
testcase_17 | AC | 3,043 ms
263,672 KB |
testcase_18 | AC | 3,311 ms
262,968 KB |
testcase_19 | AC | 3,338 ms
262,840 KB |
testcase_20 | AC | 3,328 ms
262,848 KB |
testcase_21 | AC | 3,340 ms
262,588 KB |
testcase_22 | AC | 725 ms
95,744 KB |
testcase_23 | AC | 1,191 ms
134,828 KB |
testcase_24 | AC | 1,961 ms
172,280 KB |
testcase_25 | AC | 2,383 ms
212,436 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(); } }