HDU prime number and spin-off

Prime and spin-off

topic

Problem Description
to an even split into two distinct primes, there are several demolition law?

Input
input comprising a positive even number, the value is not more than 10,000, the number does not exceed 500, the case of 0, ends.

Output
corresponding to each even output of which is split into different prime number, row for each result.

Sample Input
30
26
0

Sample Output
3
2

#include<bits/stdc++.h>
using namespace std;

bool sushu(int x){//判断是否是素数的函数,挺简单的,数大了就不好算了
    for(int i=2;i<x;i++){
        if(x%i==0)
            return 0;
    }
    return 1;

}


int main()
{
    int m;
    while (cin>>m)
    {
        int b;
        int sum=0;
        if(m==0)return 0;
       // int n=m/2;

        for(int i=2;i<=m/2;i++){//2是最小的素数//算到m/2就可以包括所有的两个数的和,然后再判断这两个数是否是素数并且不相等。
            b=m-i;
            if(sushu(i)&&sushu(b)&&i!=b)sum++;


        }
        cout<<sum<<endl;

    }


}
Published 18 original articles · won praise 0 · Views 263

Guess you like

Origin blog.csdn.net/qq_42815711/article/details/104222311