結果
| 問題 | No.843 Triple Primes | 
| コンテスト | |
| ユーザー |  ikd | 
| 提出日時 | 2019-06-28 22:59:42 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 710 bytes | 
| コンパイル時間 | 628 ms | 
| コンパイル使用メモリ | 73,728 KB | 
| 実行使用メモリ | 5,712 KB | 
| 最終ジャッジ日時 | 2024-07-02 05:05:57 | 
| 合計ジャッジ時間 | 11,935 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 RE * 1 | 
| other | AC * 6 WA * 11 RE * 25 | 
ソースコード
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
bool is_prime(int64_t x) {
  for (int64_t y = 2; y * y <= x; y++) {
    if (x % y == 0) return false;
  }
  return true;
}
int main() {
  int n;
  cin >> n;
  vector<int64_t> primes;
  for (int64_t x = 2; x <= n; x++) {
    if (is_prime(x)) primes.push_back(x);
  }
  vector<int> exists(n + 1, false);
  for (auto p : primes) {
    exists[p] = true;
  }
  int ans = 0;
  for (auto r : primes) {
    if (r * r > n * 2) break;
    for (auto p : primes) {
      auto q = r * r - p;
      if (q >= 0 and exists[q]) { ans += 1; }
    }
  }
  cout << ans << endl;
  return 0;
}
            
            
            
        