• 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);
        }
    
    }
    

      

     
     
     
  • 相关阅读:
    collections模块整理
    jQuery 事件
    前端开发问题点
    无线wifi
    MySQL 数据库--SQL语句优化
    MySQL 数据库--索引原理与慢查询优化
    MySQL 数据库--内置功能
    MySQL 数据库--权限管理
    MySQL -Naivacat工具与pymysql模块
    MySQL 数据库 -- 数据操作
  • 原文地址:https://www.cnblogs.com/Hyouka/p/5721453.html
Copyright © 2020-2023  润新知