hdu 2098 分拆素数和

分拆素数和



Problem Description

把一个偶数拆成两个不同素数的和,有几种拆法呢?

 


Input

输入包含一些正的偶数,其值不会超过10000,个数不会超过500,若遇0,则结束。

 

Output

对应每个偶数,输出其拆成不同素数的个数,每个结果占一行。

 

Sample Input

30
26
0


 
Sample Output

3
2


 


#include <iostream>
using namespace std;

int f(int n)
{int i;
for(i=2;i*i<=n;i++)
if(n%i==0) return 0;
return 1;

}

int main()
{
    int n,i,s;
    while(cin>>n,n)
    {
        s=0;
        for(i=2;i<n/2;i++)
        if(f(i)&&f(n-i)) s++;
    cout<<s<<endl;    
    }
    
}

***********************************************


#include <iostream>
using namespace std;
#define N 10000
int bz[N]={1,1,0,0,1,0};
    


void init()
{int i,j;
for(i=2;i<=N;i++)
for(j=2;i*j<=N;j++)
bz[i*j]=1;

}

int main()
{
    int n,i,s;
    init();
    while(cin>>n,n)
    {
        s=0;
        for(i=2;i<n/2;i++)
        if(bz[i]==0&&bz[n-i]==0) s++;
    cout<<s<<endl;    
    }
    
}

************************************


#include <iostream>
using namespace std;
#define N 10000
int bz[N]={1,1,0,0,1,0};
    


void init()
{int i,j;
for(i=2;i<=N;i++)
for(j=2;i*j<=N;j++)
bz[i*j]=1;

}

int main()
{
    int n,i,s;
    init();
    while(cin>>n,n)
    {
        s=0;
        for(i=2;i<n/2;i++)
        if(bz[i]==0&&bz[n-i]==0) s++;
    cout<<s<<endl;    
    }
    
}

*********************************************


#include <iostream>
using namespace std;
#define N 10000
int bz[N]={1,1,0,0,1,0};
    


void init()
{int i,j;
for(i=2;i<=N;i++)
for(j=2;i*j<=N;j++)
bz[i*j]=1;

}

int main()
{
    int n,i,s;
    init();
    while(cin>>n,n)
    {
        s=0;
        for(i=2;i<n/2;i++)
        if(bz[i]==0&&bz[n-i]==0) s++;
    cout<<s<<endl;    
    }
    
}

*********************************************


#include <iostream>
using namespace std;
#define N 10000
int bz[N]={1,1,0,0,1,0};
    


void init()
{int i,j;
for(i=2;i<=N;i++)
for(j=2;i*j<=N;j++)
bz[i*j]=1;

}

int main()
{
    int n,i,s;
    init();
    while(cin>>n,n)
    {
        s=0;
        for(i=2;i<n/2;i++)
        if(bz[i]==0&&bz[n-i]==0) s++;
    cout<<s<<endl;    
    }
    
}

******************************************



#include <iostream>
using namespace std;
#define N 10000
int bz[N]={1,1,0,0,1,0};
    


void init()
{int i,j;
for(i=2;i<=N;i++)
for(j=2;i*j<=N;j++)
bz[i*j]=1;

}

int main()
{
    int n,i,s;
    init();
    while(cin>>n,n)
    {
        s=0;
        for(i=2;i<n/2;i++)
        if(bz[i]==0&&bz[n-i]==0) s++;
    cout<<s<<endl;    
    }
    
}

*****************************************



#include <iostream>
using namespace std;
#define N 10000
int bz[N]={1,1,0,0,1,0};
    


void init()
{int i,j;
for(i=2;i<=N;i++)
for(j=2;i*j<=N;j++)
bz[i*j]=1;

}

int main()
{
    int n,i,s;
    init();
    while(cin>>n,n)
    {
        s=0;
        for(i=2;i<n/2;i++)
        if(bz[i]==0&&bz[n-i]==0) s++;
    cout<<s<<endl;    
    }
    
}

  

  

  

原文地址:https://www.cnblogs.com/wc1903036673/p/3431988.html