結果
| 問題 | No.843 Triple Primes | 
| コンテスト | |
| ユーザー |  ldsyb | 
| 提出日時 | 2019-06-28 22:47:40 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 550 bytes | 
| コンパイル時間 | 1,552 ms | 
| コンパイル使用メモリ | 169,420 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-02 05:03:09 | 
| 合計ジャッジ時間 | 7,877 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 40 WA * 2 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int64_t n;
	cin >> n;
	vector<int64_t> ps;
	ps.emplace_back(2);
	for (int64_t i = 3; i <= n; i += 2)
	{
		bool f = true;
		for (auto &p : ps)
		{
			if (i < p * p)
			{
				break;
			}
			f &= i % p != 0;
		}
		if (f)
		{
			ps.emplace_back(i);
		}
	}
	int64_t ans = 0;
	for (auto &x : ps)
	{
		int64_t r = x * x;
		auto itr = lower_bound(ps.begin(), ps.end(), r - 2);
		if (itr != ps.end() && (*itr == r - 2))
		{
			ans++;
		}
	}
	ans *= 2;
	ans--;
	cout << ans << endl;
	return 0;
}
            
            
            
        