結果

問題 No.843 Triple Primes
ユーザー trineutron
提出日時 2019-06-29 17:39:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 441 bytes
コンパイル時間 1,592 ms
コンパイル使用メモリ 166,824 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-19 14:12:59
合計ジャッジ時間 2,630 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

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 < 2) {
        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