【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. 打通MySQL的操作权限

    打通MySQL的操作权限 前面已经总结了<XAMPP的配置与使用>,虽然可以直接通过GUI控制面板去启动MySQL服务,但是有些相关的操作则需要在Windows中的CMD命令窗口中去对My ...

  2. Pycharm 出现Unresolved reference '' 错误的解决方法

    在用Pycharm做Pygame游戏小实战的时候碰到一个很无语的问题 如下 什么鬼?????? 我明明有写settings模块啊 而且还是放在同一个目录下  然后Pycharm给我来了一个错误 而且在 ...

  3. 一个简单的定时表达式(HH:mm:ss)解析

    前言 为客户开发了一个日志监控程序,监听各频道是否正常工作.其中有一个功能是这样的,当所有频道正常运行一段时间后,语音提示值班人员系统运行正常.一开始,想法比较简单,设置了一个变量,在线程不断轮询的过 ...

  4. Git版本控制的基本命令

    安装完了GIT首先要自报家门,否则代码不能提交 git config --global user.name "Your Name" git config --global user ...

  5. github的拉取、提交,创建分支与合并

    前期准备: 1.安装git  官网地址:https://git-scm.com/(下载下来,直接下一步)   2.github账号(这有点废话)   3.配置github密钥 下载及安装好git后,右 ...

  6. JDBC批量插入优化addbatch

    // 获取要设置的Arp基准的List后,插入Arp基准表中 public boolean insertArpStandardList(List<ArpTable> list) { Con ...

  7. 恢复Mysql丢失的root用户权限

      今天安装了某个程序时, 由于程序很傻X的 新建了一个 root@localhost 用户 并把 root权限全部改为了 no 这下 我也 傻X 了.服务器上所有程序都崩溃了. 此时即使用root用 ...

  8. linux云计算(keystone swift cinder配置)

    独立安装openstack组件 准备服务器,为安装openstack的服务器加3块额外硬盘 qemu-img create -f qcow2 rh71.img 20G qemu-img create ...

  9. linux rsync实时同步

    rsync同步 同步与复制的差异:复制:完全拷贝源到目标同步:增量拷贝,只传输变化过的数据 同步操作:remote sync 远程同步支持本地复制,或与其他ssh,rsync主机同步.官方网站:htt ...

  10. python调试

    如果很简单的程序,建议还是pirnt打出来. 对于Linux环境,使用pdb/ipdb是一个不错的选择. 安装ipdb sudo pip install ipdb 开启调试 手动在需要调试的地方写入s ...