zoukankan      html  css  js  c++  java
  • hdu 5104 素数打表水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5104

    找元组数量,满足p1<=p2<=p3且p1+p2+p3=n且都是素数


    不用素数打表都能过,数据弱的一比

    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <string>
    #include <queue>
    #include <map>
    #include <iostream>
    #include <sstream>
    #include <algorithm>
    using namespace std;
    #define RD(x) scanf("%d",&x)
    #define RD2(x,y) scanf("%d%d",&x,&y)
    #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
    #define clr0(x) memset(x,0,sizeof(x))
    #define clr1(x) memset(x,-1,sizeof(x))
    #define eps 1e-9
    const double pi = acos(-1.0);
    typedef long long LL;
    const int inf = 0x7fffffff;
    const int maxn = 1e5+5;
    int p[maxn],pr[maxn],cnt = 0;
    int n;
    void init()
    {
        clr0(p);
        for(int i = 2;i < maxn;++i){
            if(!p[i]){
                for(int j = i + i;j < maxn;j+=i)
                    p[j] = 1;
            }
        }
        p[0] = 1;
        for(int i = 2;i < maxn;++i)
            if(!p[i])
                pr[cnt++] = i;
    }
    int main()
    {
        init();//cout<<cnt;
        while(~RD(n)){
            LL ans = 0;
            for(int i = 0;i < cnt;++i){
                if(n < pr[i]*3)
                    break;
                for(int j = i;j < cnt;++j){
                    int k = n - pr[i] - pr[j];
                    if(pr[j] > k)
                        break;
                    //printf("%d %d %d 
    ",pr[i],pr[j],k);
                    if(!p[k])
                        ans++;
                }
            }
            printf("%I64d
    ",ans);
        }
        return 0;
    }
    


  • 相关阅读:
    python处理excel文件
    Python datetime模块
    OrderedDict 有序字典以及读取json串时如何保持原有顺序
    ansible 学习笔记
    nginx的location和rewrite
    实体机重装系统
    热词
    教育
    生活
    1、两数之和
  • 原文地址:https://www.cnblogs.com/zibaohun/p/4106644.html
Copyright © 2011-2022 走看看