素数对——腾讯

#include<iostream>
using namespace std;
bool iszhishu(int n)
{
    if(n < 2) return false;
    for(int i = 2; i < n/2; i++)
    {
        if(n % i == 0)
            return false;
    }
    return true;
}
int main()
{
    int A;
    int count = 0;
    cin >> A;
    for(int i = 1; i <= A/2; i++)
    {
        if(iszhishu(i))
        {
            int j = A - i;
            if(iszhishu(j))
                count++;
        }
    }
    cout << count << endl;
    
    return 0;
}

注意:

(1)1既不是素数也不是合数;

(2)开始判断质数的函数 return false 与 return true写反了,答案不对

猜你喜欢

转载自blog.csdn.net/Eartha1995/article/details/82313308
今日推荐