zoukankan      html  css  js  c++  java
  • HDU 2098 分拆素数和 数论

    分拆素数和
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
     

    Description

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

    Input

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

    Output

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

    Sample Input

    30
    26
    0
     

    Sample Output

    3
    2
     
    关键是做一下预处理
     
     
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <iomanip>
    #include <math.h>
    using namespace std;
    #define FIN     freopen("input.txt","r",stdin);
    #define INF     0x3f3f3f3f
    #define lson    l,m,rt<<1
    #define rson    m+1,r,rt<<1|1
    typedef long long LL;
    
    int p[10005];
    int s[5005];
    
    int main()
    {
        //FIN
        int cas=0;
        for(int i=2; i<=10000; i++)
        {
            if(p[i]==0)
            {
                for(int j=i+i; j<=10000; j=j+i)
                {
                    p[j]=1;
                }
            }
        }
        for(int i=2; i<=10000; i++)
        {
            if(p[i]==0)
                s[cas++]=i;
        }
    
        int n;
        while(~scanf("%d",&n)&&n)
        {
            int cnt=0;
            for(int i=3; i<n/2; i+=2)
            {
                if(!p[i]&&!p[n-i])
                    cnt++;
            }
            printf("%d
    ",cnt);
        }
    
    }
    

      

     
     
     
  • 相关阅读:
    管理~资源组织运作
    科学与艺术区别
    概念思维
    拨开文字表象,关注背后事实
    论信息部门与业务部门的关系
    再论信息系统
    linux命令行快捷键记录
    hadoop,帮我解了部分惑的文章
    hadoop运行测试命令遇到的问题
    日志分析及几个小技巧
  • 原文地址:https://www.cnblogs.com/Hyouka/p/5721453.html
Copyright © 2011-2022 走看看