結果
問題 |
No.732 3PrimeCounting
|
ユーザー |
![]() |
提出日時 | 2019-04-30 16:58:45 |
言語 | C (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 770 bytes |
コンパイル時間 | 1,813 ms |
コンパイル使用メモリ | 29,440 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-30 11:35:12 |
合計ジャッジ時間 | 5,684 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 88 WA * 1 |
ソースコード
// yukicoder: No.732 3PrimeCounting // 2019.4.30 bal4u #include <stdio.h> #define MAX 300005 #define SQRT 547 char notPrime[MAX] = { 1,1,0,0,1 }; // zero: if prime int ptbl[26000] = { 2 }; int sz; // 25997 void sieve(int n) { int i, j, b; for (i = 3; i <= SQRT; i += 2) if (!notPrime[i]) { for (j = i * i; j <= n; j += i) notPrime[j] = 1; } sz = 1; for (i = 3; i <= n; 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; scanf("%d", &N); sieve(3*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; }