結果
問題 |
No.732 3PrimeCounting
|
ユーザー |
![]() |
提出日時 | 2021-01-25 21:10:11 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 521 ms / 3,000 ms |
コード長 | 1,048 bytes |
コンパイル時間 | 3,483 ms |
コンパイル使用メモリ | 78,056 KB |
実行使用メモリ | 56,684 KB |
最終ジャッジ日時 | 2024-06-22 17:21:33 |
合計ジャッジ時間 | 24,377 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 89 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); boolean[] isNotPrime = new boolean[n * 3 + 1]; ArrayList<Integer> primes = new ArrayList<>(); for (int i = 2; i < isNotPrime.length; i++) { if (!isNotPrime[i]) { primes.add(i); for (int j = 2; j * i < isNotPrime.length; j++) { isNotPrime[j * i] = true; } } } int[] counts = new int[n * 3 + 1]; counts[5] = 1; long ans = 0; for (int i = 2; primes.get(i) <= n; i++) { int x = primes.get(i); for (int j = i + 1; j < primes.size() && primes.get(j) < 3 * x; j++) { ans += counts[primes.get(j) - x]; } for (int j = 0; j < i; j++) { int y = primes.get(j); counts[x + y]++; } } System.out.println(ans); } }