結果
問題 | No.732 3PrimeCounting |
ユーザー |
|
提出日時 | 2018-09-07 23:07:32 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 696 ms / 3,000 ms |
コード長 | 1,252 bytes |
コンパイル時間 | 849 ms |
コンパイル使用メモリ | 118,712 KB |
実行使用メモリ | 7,296 KB |
最終ジャッジ日時 | 2024-06-13 01:38:45 |
合計ジャッジ時間 | 9,591 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 89 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;import std.typecons, std.range, std.random, std.math, std.container;import std.numeric, std.bigint, core.bitop, std.bitmanip;immutable long MOD = 10^^9 + 7;immutable long INF = 1L << 59;void main() {auto N = readln.chomp.to!int;int[] P;auto is_P = new bool[](3*N+1);fill(is_P, true);is_P[0] = is_P[1] = false;foreach (i; 2..3*N+1) {if (!is_P[i]) continue;P ~= i;for (int j = i + i; j < 3*N+1; j += i) is_P[j] = false;}int M = P.length.to!int;auto P1 = P.filter!(p => p <= N && p % 3 == 1).array;auto P2 = P.filter!(p => p <= N && p % 3 == 2 && p != 2).array;auto A = new long[](3*N+1);auto B = new long[](3*N+1);foreach (i; 0..P1.length) foreach (j; i+1..P1.length) A[P1[i]+P1[j]] += 1;foreach (i; 0..P2.length) foreach (j; i+1..P2.length) B[P2[i]+P2[j]] += 1;long ans = 0;foreach (p; P) if (p >= 3) ans += A[p - 3] + B[p - 3];foreach (p1; P1) foreach (p; P) if (p - p1 > 0) ans += B[p - p1]; //, writeln(p, " ", p1, " ", B[p - p1]);foreach (p2; P2) foreach (p; P) if (p - p2 > 0) ans += A[p - p2]; //, writeln(p, " ", p2, " ", A[p - p2]);ans.writeln;}