結果
問題 | No.732 3PrimeCounting |
ユーザー |
![]() |
提出日時 | 2019-04-30 17:10:35 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 139 ms / 3,000 ms |
コード長 | 768 bytes |
コンパイル時間 | 312 ms |
コンパイル使用メモリ | 29,952 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-30 12:33:42 |
合計ジャッジ時間 | 4,481 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 89 |
ソースコード
// yukicoder: No.732 3PrimeCounting // 2019.4.30 bal4u #include <stdio.h> #define MAX 300000 #define SQRT 547 char notPrime[MAX+2] = { 1,1,0,0,1 }; // zero: if prime int ptbl[26000] = { 2 }; int sz; // 25997 void sieve() { int i, j, b; for (i = 3; i <= SQRT; i += 2) if (!notPrime[i]) { for (j = i * i; j <= MAX; j += i) notPrime[j] = 1; } sz = 1; for (i = 3; i <= MAX; i += 2) { if (!notPrime[i]) ptbl[sz++] = i; } } int f[300005]; int main() { int N, i, j, a, b, c, d, t; long long ans; sieve(); scanf("%d", &N); ans = 0; for (i = 3; (c = ptbl[i]) <= N; i++) { b = ptbl[i-1], t = ptbl[i-2] + b + c; a = i-2; while (a) f[ptbl[a--] + b]++; for (j = i+1; (d = ptbl[j]) <= t; j++) ans += f[d-c]; } printf("%lld\n", ans); return 0; }