PAT_乙级_1007

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lzc842650834/article/details/86652407

1007 素数对猜想

题目复制有乱码,就不再累述了,很基础的一道题。

#include<iostream>
#include<math.h>
using namespace std;
//判断是否是素数
int judge(int num)
{
    int temp = sqrt(num);
    if (num == 2) {
        return 1;
    } else {
        for (int i = 2; i <= temp; i++) {
            if (num % i == 0) {
                return 0;
            }
        }
    }
    return 1;

}
int main()
{
    int N;
    int count = 0;
    cin >> N;
    for (int i = 3; i <= N - 2; i += 2) {
        if (judge(i)) {
            if (judge(i + 2)) {
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/lzc842650834/article/details/86652407
今日推荐