結果
| 問題 | No.732 3PrimeCounting |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-21 23:23:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,134 bytes |
| 記録 | |
| コンパイル時間 | 712 ms |
| コンパイル使用メモリ | 77,924 KB |
| 実行使用メモリ | 7,852 KB |
| 最終ジャッジ日時 | 2025-12-21 23:27:58 |
| 合計ジャッジ時間 | 257,374 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 68 WA * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
32 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 100000;
int n, freq[3 * N + 10], ma;
LL ans;
vector<int> primes;
bool is_prime[3 * N + 10];
void SievePrime() {
fill(is_prime, is_prime + N + 1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= 3 * N; ++i) {
if (is_prime[i]) primes.push_back(i);
for (auto p : primes) {
if (1LL * i * p > N) continue;
is_prime[i * p] = false;
if (i % p == 0) break;
}
}
}
int main() {
SievePrime();
scanf("%d", &n);
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;
}