結果
| 問題 | No.732 3PrimeCounting |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-21 23:30:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2,730 ms / 3,000 ms |
| コード長 | 1,126 bytes |
| 記録 | |
| コンパイル時間 | 759 ms |
| コンパイル使用メモリ | 78,068 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-12-21 23:30:53 |
| 合計ジャッジ時間 | 30,334 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 89 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 300010;
int n, freq[N], ma;
LL ans;
vector<int> primes;
bool is_prime[N];
void SievePrime(int sz) {
fill(is_prime, is_prime + sz, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= sz; ++i) {
if (is_prime[i]) primes.push_back(i);
for (auto p : primes) {
if (1LL * i * p > sz) continue;
is_prime[i * p] = false;
if (i % p == 0) break;
}
}
}
int main() {
scanf("%d", &n);
SievePrime(n * 3);
ans = 0LL;
for (int i = 2; i < primes.size() && primes[i] <= n; ++i) {
int c = primes[i];
int b = primes[i - 1]; // b更小的前面已经构造过了
for (int j = 0; j < i - 1; ++j) {
int a = primes[j];
++freq[a + b];
}
for (int j = 0; j < primes.size(); ++j) {
int sum = primes[j];
if (sum - c >= 0) {
ans += freq[sum - c];
}
}
}
printf("%lld\n", ans);
return 0;
}