/*
* @Author: 365JHWZGo
* @Description: 1007 素数对猜想 (20 分)
* @Date: 2021-09-02 10:36:18
* @FilePath: \VScodeC++practice\PAT\sushuAssume.cpp
* @LastEditTime: 2021-09-02 11:35:19
* @LastEditors: 365JHWZGo
*/
#include <iostream>
#include <math.h>
using namespace std;
bool judge(int n)
{
//最后一个测试点要使用sqrt(n)+1,否则运行超时
for (int i = 2; i < sqrt(n) + 1; i++)
{
if (n % i == 0)
return false;
}
return true;
}
int main()
{
//std::ios::sync_with_stdio(false);
int num, ans = 0;
cin >> num;
int before = 2, now = 0;
//i<=num,否则当等于num时不执行
for (int i = 3; i <= num; i += 2)
{
if (judge(i))
{
now = i;
if (now - before == 2)
ans++;
before = now;
}
}
cout << ans;
return 0;
}
1007 素数对猜想 (20 分)满分!
最新推荐文章于 2024-09-08 15:17:59 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)