結果

問題 No.843 Triple Primes
ユーザー pionepione
提出日時 2019-06-28 22:25:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,660 bytes
コンパイル時間 2,847 ms
コンパイル使用メモリ 163,260 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 17:47:39
合計ジャッジ時間 5,251 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 49 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 36 ms
4,348 KB
testcase_08 AC 41 ms
4,348 KB
testcase_09 AC 49 ms
4,348 KB
testcase_10 AC 38 ms
4,348 KB
testcase_11 AC 44 ms
4,348 KB
testcase_12 AC 47 ms
4,348 KB
testcase_13 AC 45 ms
4,348 KB
testcase_14 AC 45 ms
4,348 KB
testcase_15 AC 37 ms
4,348 KB
testcase_16 AC 38 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 10 ms
4,348 KB
testcase_21 AC 6 ms
4,348 KB
testcase_22 AC 23 ms
4,348 KB
testcase_23 AC 24 ms
4,348 KB
testcase_24 AC 10 ms
4,348 KB
testcase_25 AC 8 ms
4,348 KB
testcase_26 AC 48 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 46 ms
4,348 KB
testcase_29 AC 11 ms
4,348 KB
testcase_30 AC 47 ms
4,348 KB
testcase_31 AC 4 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 13 ms
4,348 KB
testcase_34 AC 21 ms
4,348 KB
testcase_35 AC 49 ms
4,348 KB
testcase_36 AC 7 ms
4,348 KB
testcase_37 AC 35 ms
4,348 KB
testcase_38 AC 27 ms
4,348 KB
testcase_39 AC 47 ms
4,348 KB
testcase_40 AC 1 ms
4,348 KB
testcase_41 AC 1 ms
4,348 KB
testcase_42 AC 40 ms
4,348 KB
testcase_43 AC 44 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPS(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define RREPS(i, n) for (int i = ((int)(n)); i > 0; i--)
#define IREP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define IREPS(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVISORT(v) sort(v.begin(), v.end(), greater<int>());
#define ALL(v) v.begin(), v.end()

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;

typedef long long ll;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const ll mod=1e9+7;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

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

    return true;
}

int main()
{
    cin.tie( 0 );
    ios::sync_with_stdio( false );
	
	int n;
	cin>>n;

	VI v;
	for(int i=2;i<=n;i++){
		if(IsPrime(i))v.push_back(i);
	}

	// REP(i,v.size())cout<<v[i]<<endl;
	int ans=0;
	REP(i,v.size()){
		int r=v[i]*v[i];
		if(r>n+2)break;
		for(int j=0;j<v.size()&&v[j]<r;j++){
			int p=v[j];
			int q=r-p;
			if(IsPrime(q)){
				ans++;
				// cout << p << "," << q << "," << r << endl;
			}
		}
	}

	cout << ans << endl;
    return 0;
}
0