結果

問題 No.843 Triple Primes
ユーザー trineutron
提出日時 2019-06-29 17:39:03
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 441 bytes
コンパイル時間 1,672 ms
コンパイル使用メモリ 167,440 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-02 05:36:18
合計ジャッジ時間 2,872 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 40 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

bool isprime(int n)
{
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main()
{
    int n, p = 0;
    cin >> n;
    if (n < 4) {
        cout << 0 << endl;
        return 0;
    }
    for (int r = 2; r * r - 2 <= n; r++) {
        if (isprime(r) && isprime(r * r - 2)) p++;
    }
    cout << 2 * p - 1 << endl;
}
0