結果

問題 No.843 Triple Primes
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-06-28 21:44:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 2,088 bytes
コンパイル時間 1,839 ms
コンパイル使用メモリ 172,892 KB
実行使用メモリ 5,604 KB
最終ジャッジ日時 2023-10-19 17:39:04
合計ジャッジ時間 3,701 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 25 ms
5,604 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 19 ms
5,216 KB
testcase_08 AC 22 ms
5,364 KB
testcase_09 AC 25 ms
5,592 KB
testcase_10 AC 20 ms
5,276 KB
testcase_11 AC 23 ms
5,444 KB
testcase_12 AC 25 ms
5,548 KB
testcase_13 AC 24 ms
5,496 KB
testcase_14 AC 24 ms
5,496 KB
testcase_15 AC 20 ms
5,244 KB
testcase_16 AC 21 ms
5,264 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 6 ms
4,348 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 13 ms
4,664 KB
testcase_23 AC 14 ms
4,712 KB
testcase_24 AC 7 ms
4,348 KB
testcase_25 AC 6 ms
4,348 KB
testcase_26 AC 25 ms
5,588 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 24 ms
5,516 KB
testcase_29 AC 7 ms
4,348 KB
testcase_30 AC 25 ms
5,560 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 8 ms
4,348 KB
testcase_34 AC 12 ms
4,576 KB
testcase_35 AC 25 ms
5,592 KB
testcase_36 AC 5 ms
4,348 KB
testcase_37 AC 19 ms
5,092 KB
testcase_38 AC 15 ms
4,852 KB
testcase_39 AC 24 ms
5,532 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 21 ms
5,316 KB
testcase_43 AC 23 ms
5,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
vector<int> makePrimes(int n) { // [2,n]
	vector<int> res, pr(n + 1, 1);
	pr[0] = pr[1] = 0;
	rep(p, 2, sqrt(n) + 2) if (pr[p]) for (int x = p * 2; x <= n; x += p) pr[x] = 0;
	rep(p, 2, n + 1) if (pr[p]) res.push_back(p);
	return res;
}
vector<bool> makePrimesBool(int n) { // [2,n]
	vector<bool> pr(n + 1, 1);
	pr[0] = pr[1] = 0;
	rep(p, 2, sqrt(n) + 2) if (pr[p]) for (int x = p * 2; x <= n; x += p) pr[x] = 0;
	return pr;
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/











int N, M;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	M = sqrt(2 * N) + 5;

	auto vp_n = makePrimes(N);
	auto vp_m = makePrimes(M);
	auto vpb_n = makePrimesBool(N);

	int ans = 0;
	fore(p, vp_n) fore(r, vp_m) if(p <= N and r <= N) {
		int q = r * r - p;
		if (0 <= q and vpb_n[q] and q <= N) ans++;
	}
	cout << ans << endl;
}


0