結果
問題 |
No.1514 Squared Matching
|
ユーザー |
![]() |
提出日時 | 2024-08-06 13:33:46 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,889 bytes |
コンパイル時間 | 3,857 ms |
コンパイル使用メモリ | 78,424 KB |
実行使用メモリ | 446,776 KB |
最終ジャッジ日時 | 2024-08-06 13:34:02 |
合計ジャッジ時間 | 15,409 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 WA * 23 |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] values = new int[n + 1]; for (int i = 1; i <= n; i++) { values[i] = i; } boolean[] isNotPrimes = new boolean[10000]; for (int i = 2; i * i <= n; i++) { if (!isNotPrimes[i]) { for (int j = 2; j * i < isNotPrimes.length; j++) { isNotPrimes[j * i] = true; } for (int j = 1; i * i * j <= n; j++) { values[i * i * j] /= i * i; } } } int[] counts = new int[n + 1]; for (int i = 1; i <= n; i++) { counts[values[i]]++; } long ans = 0; for (int x : counts) { ans += x * (x - 1L) / 2 * 2; } System.out.print(ans + n); } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }