zoukankan      html  css  js  c++  java
  • hdu 5104 Primes Problem (素数 打表 水)

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

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int isp[10000+100];
    int prime[10000];
    int coun;
    bool isprime(int x)
    {
      int i,j;
      for(i=2;i<=sqrt(x);i++)
      {
        if(x%i==0) return false;
      }
      return true;
    }
    void fun()
    {
      int i,j;
      for(i=2;i<=10000;i++)
      {
        if(isp[i]!=0) continue;
        if(isprime(i))
        {
            isp[i]=1;
            prime[coun++]=i;
        }
        j=i;
        while(j+i<=10000)
        {
          j+=i;
          isp[j]=2;
        }
      }
    }
    int main()
    {
      //freopen("output.txt","w",stdout);
      int ans;
      int i,j,k,n;
      memset(isp,0,sizeof(isp));
      coun=0;
      fun();
      //printf("%d...
    ",coun);
      while(scanf("%d",&n)!=EOF)
      {
        int ans=0;
        for(i=0;i<coun;i++)
        {
          if(prime[i]>n/3) break;
            for(j=i;prime[j]<=(n-prime[i])/2;j++)
            {
                k=n-prime[i]-prime[j];
                if(isp[k]==1) ans++;
            }
        }
        printf("%d
    ",ans);
        //n++;
      }
      return 0;
    }
    View Code
  • 相关阅读:
    curl
    Bazel 国内镜像源加速下载 + 编译gvisor
    go proxy 代理
    netstack gvisor
    rust libc
    gVisor in depth
    Unikernel
    Unikernel初体验
    github 文本编辑
    cloud-hypervisor coredump
  • 原文地址:https://www.cnblogs.com/sola1994/p/4231778.html
Copyright © 2011-2022 走看看