zoukankan      html  css  js  c++  java
  • 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;    
        }
        
    }
    
      
    
      
    

      

  • 相关阅读:
    ArcGIS10新功能体验
    GP(Geoprocessing)服务的发布与调用
    ArcGIS10新体验之地图编辑
    ArcGIS10新功能之制作地图集
    推荐几本GIS专业书籍
    ArcGIS时态数据应用——动态展示台风中心轨迹
    为gridview“删除”列添加确认对话框
    (转)面向对象设计思想(C#)
    数据库Oracle与SqlServer与Access
    Oracle日期时间加减法运算
  • 原文地址:https://www.cnblogs.com/wc1903036673/p/3431988.html
Copyright © 2011-2022 走看看