結果

問題 No.732 3PrimeCounting
コンテスト
ユーザー 梧桐
提出日時 2025-12-23 22:30:53
言語 C++14
(gcc 13.3.0 + boost 1.89.0)
結果
RE  
実行時間 -
コード長 1,226 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 671 ms
コンパイル使用メモリ 71,652 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2025-12-23 22:31:21
合計ジャッジ時間 27,430 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 68 WA * 3 RE * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:36:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

const int N = 100010;

int n, freq[N];
LL ans;
bool is_prime[N];
vector<int> primes;

void EulerSieve(int x) {
    fill(is_prime, is_prime + N, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i < x; ++i) {
        if (is_prime[i]) primes.push_back(i);
        for (auto p : primes) {
            if (1LL * i * p >= x) continue;
            is_prime[i * p] = false;
            if (i % p == 0) {
                break;
            }
        }
    }
}

// 1 - 100000有9527个质数
int main() {
    // freopen("psum.in", "r", stdin);
    // freopen("psum.out", "w", stdout);
    
    scanf("%d", &n);

    EulerSieve(3 * n);

    for (int i = 2; i < primes.size() && primes[i] <= n; ++i) {
        int c = primes[i];
        int b = primes[i - 1];
        for (int j = 0; j < i - 1; ++j) {
            int a = primes[j];
            ++freq[a + b];
        }
        for (int j = 0; j < primes.size() && primes[j] <= 3 * c; ++j) {
            int sum = primes[j];
            if (sum >= c) {
                ans += freq[sum - c];
            }
        }
    }

    printf("%lld\n", ans);

    return 0;
}
0