【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\n",ans);
}
return 0;
}

【LightOJ1259】Goldbach`s Conjecture(数论)的更多相关文章

  1. LightOJ-1259 Goldbach`s Conjecture 数论 素数筛

    题目链接:https://cn.vjudge.net/problem/LightOJ-1259 题意 给一个整数n,问有多少对素数a和b,使得a+b=n 思路 素数筛 埃氏筛O(nloglogn),这 ...

  2. LightOJ1259 Goldbach`s Conjecture —— 素数表

    题目链接:https://vjudge.net/problem/LightOJ-1259 1259 - Goldbach`s Conjecture    PDF (English) Statistic ...

  3. LightOJ1259 Goldbach`s Conjecture

    题面 T组询问,每组询问是一个偶数n 验证哥德巴赫猜想 回答n=a+b 且a,b(a<=b)是质数的方案个数 Input Input starts with an integer T (≤ 30 ...

  4. Goldbach`s Conjecture(LightOJ - 1259)【简单数论】【筛法】

    Goldbach`s Conjecture(LightOJ - 1259)[简单数论][筛法] 标签: 入门讲座题解 数论 题目描述 Goldbach's conjecture is one of t ...

  5. [暑假集训--数论]poj2262 Goldbach's Conjecture

    In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in whic ...

  6. F - Goldbach`s Conjecture kuangbin 基础数论

    Goldbach's conjecture is one of the oldest unsolved problems in number theory and in all of mathemat ...

  7. LightOJ - 1259 - Goldbach`s Conjecture(整数分解定理)

    链接: https://vjudge.net/problem/LightOJ-1259 题意: Goldbach's conjecture is one of the oldest unsolved ...

  8. Goldbach's Conjecture

     Goldbach's Conjecture Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I ...

  9. Poj 2262 / OpenJudge 2262 Goldbach's Conjecture

    1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...

随机推荐

  1. yii2 源码分析 object类分析 (一)

    转载请注明链接http://www.cnblogs.com/liuwanqiu/p/6737327.html yii2基本上所有的类都是继承的object类,下面就来分析一下object类吧 obje ...

  2. javac编译乱码

    PersonTest.java:1: 错误: 非法字符: \65279 解决途径如下 用记事本打开java源文件,另存为ANSI格式 如果java文件包含中文字符,使用-encoding gbk格式进 ...

  3. wampserve部署

    全名 WampServer 来自法国的软件 http://www.wampserver.com/en/ 一.下载方法: 1.一级导航点击download(发现只不过是本页的跳转,硕大的 wampser ...

  4. bzoj 1814 Ural 1519 Formula 1 插头DP

    1814: Ural 1519 Formula 1 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 942  Solved: 356[Submit][Sta ...

  5. Ubuntu14.04上安装Composer

    1,查看机子上有没有安装php 2,下载Composer的安装包 3,安装Composer 4,设置Composer全局可访问

  6. CNN 卷积层输入Map大小计算

    对于输出的size计算: out_height=((input_height - filter_height + padding_top+padding_bottom)/stride_height ) ...

  7. SPFA+SLF+LLL优化模板

    #include<algorithm> #include <iostream> #include <cstdlib> #include <cstring> ...

  8. JAVA多线程与并发学习总结

    1.      计算机系统 使用高速缓存来作为内存与处理器之间的缓冲,将运算需要用到的数据复制到缓存中,让计算能快速进行:当运算结束后再从缓存同步回内存之中,这样处理器就无需等待缓慢的内存读写了. 缓 ...

  9. HADOOP集群配置

    http://wenku.baidu.com/view/92cbe435eefdc8d376ee32eb.html http://www.infoq.com/cn/articles/hadoop-co ...

  10. 我的Java设计模式-建造者模式

    在未上大学之前,一直有个梦想"I have a dream!",就是能成为一位汽车工程师,一直幻想着开着自己设计的汽车飞奔在公路上,迷倒了万千少女.咳咳~~虽然现在没实现我的dre ...