結果

問題 No.843 Triple Primes
ユーザー gon_027
提出日時 2019-09-10 22:25:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 750 bytes
コンパイル時間 520 ms
コンパイル使用メモリ 69,856 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-07-02 16:26:37
合計ジャッジ時間 4,240 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 TLE * 1
other -- * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
using namespace std;

bool isPrime(int n){
    if (n <= 1)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;

    int num = sqrt(n);
    for (int i = 3; i <= num; i += 2)
    {
        if (n % i == 0)
            return false;
    }

    return true;
}

int main(){
    int n; cin >> n;

    int count = 0;
    for(int p = 2; p <= n; p++){
        for(int r = 2; r <= n; r++){
            int q = (r * r) - p;
            if(q >= 2 && q <= n && isPrime(p) && isPrime(q) && isPrime(r)){
                //cout << "( " << p << " , " << q << " , " << r << " )" << endl;
                count++;
            }
        }
    }

    cout << count << endl;

}
0