zoukankan      html  css  js  c++  java
  • 【LightOJ1259】Goldbach`s Conjecture(数论)

    【LightOJ1259】Goldbach`s Conjecture(数论)

    题面

    Vjudge
    T组询问,每组询问是一个偶数n
    验证哥德巴赫猜想
    回答n=a+b
    且a,b(a<=b)是质数的方案个数

    题解

    筛出质数后直接暴力判断就行了
    质数密度没有那么大,记得节约空间

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<set>
    #include<map>
    #include<vector>
    #include<queue>
    using namespace std;
    #define MAX 10000000
    inline int read()
    {
    	int x=0,t=1;char ch=getchar();
    	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    	if(ch=='-')t=-1,ch=getchar();
    	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    	return x*t;
    }
    int pr[MAX/10],tot;
    bool zs[MAX+1000];
    void Pre()
    {
    	zs[1]=true;
    	for(int i=2;i<=MAX;++i)
    	{
    		if(!zs[i])pr[++tot]=i;
    		for(int j=1;j<=tot&&i*pr[j]<=MAX;++j)
    		{
    			zs[i*pr[j]]=true;
    			if(i%pr[j]==0){break;}
    		}
    	}
    }
    int main()
    {
    	Pre();
    	int T=read();
    	for(int gg=1;gg<=T;++gg)
    	{
    		printf("Case %d: ",gg);
    		int n=read(),ans=0;
    		for(int j=1;j<=tot&&pr[j]<n&&pr[j]<=n-pr[j];++j)
    			if(!zs[n-pr[j]])++ans;
    		printf("%d
    ",ans);
    	}
    	return 0;
    }
    
    
  • 相关阅读:
    基本语句
    mysql多表查询方法(join)
    MySQL JOIN 多表连接
    MySQL SHOW INDEX语法的实际应用
    1.索引作用
    MySQL索引和优化查询
    mysql复合索引、普通索引总结
    mysql 索引相关
    for循环的break和continue
    保护程序猿滴眼睛---修改VS 2012 编辑器颜色
  • 原文地址:https://www.cnblogs.com/cjyyb/p/8250450.html
Copyright © 2011-2022 走看看