【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. CentOS 7 搭建基于携程Apollo(阿波罗)配置中心单机模式

    Apollo(阿波罗)是携程框架部门研发的配置管理平台,能够集中化管理应用不同环境.不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限.流程治理等特性.服务端基于Spring Boot ...

  2. mac攻略(4) -- 使用brew配置php7开发环境(mac+php+apache+mysql+redis)

    [http://www.cnblogs.com/redirect/p/6131751.html] 网上有很多文章都是错误的,因为是copy别人的,作者没有自己亲测,不仅不能给新手提供帮助,还会产生严重 ...

  3. map,vector 等容器内容的循环删除问题(C++)

    map,vector 等容器内容的循环删除问题(C++) map,vector等容器的循环删除不能用普通的方法删除: for(auto p=list.begin();p!=list.end();p++ ...

  4. 洛谷 P2073 送花【Treap】题解+AC代码

    题目背景 小明准备给小红送一束花,以表达他对小红的爱意.他在花店看中了一些花,准备用它们包成花束. 题目描述 这些花都很漂亮,每朵花有一个美丽值W,价格为C. 小明一开始有一个空的花束,他不断地向里面 ...

  5. makefile讲解

    仅供自己学习使用 一.Makefile介绍 Makefile 或 makefile: 告诉make维护一个大型程序, 该做什么.Makefile说明了组成程序的各模块间的相互 关系及更新模块时必须进行 ...

  6. UVA - 1218 Perfect Service (树形DP)

    思路:dp[i][0]表示i是服务器:dp[i][1]表示i不是服务器,但它的父节点是服务器:dp[i][2]表示i和他的父亲都不是服务器.       转移方程: d[u][0] += min(d[ ...

  7. c# 委托(Func、Action)

    以前自己写委托都用 delegate, 最近看组里的大佬们都用 Func , 以及 Action 来实现, 代码简洁了不少, 但是看得我晕晕乎乎. 花点时间研究一下,记录一下,以便后期的查阅. 1.F ...

  8. JVM笔记5-对象的访问定位。

    java虚拟机中指定一个栈内存的引用指向了堆内存中的对象.这样说只是笼统的说法.而指向堆内存中的对象就一定是栈引用所需要的那个对象吗?其实并不定. 这就需要知道对象的访问定位方式有两种: 1.使用句柄 ...

  9. Hadoop序列化与Java序列化

    序列化就是把内存中的对象的状态信息转换成字节序列,以便于存储(持久化)和网络传输 反序列化就是就将收到的字节序列或者是硬盘的持久化数据,转换成内存中的对象. 1.JDK的序列化 只要实现了serial ...

  10. 网络基础Cisco路由交换三

    热备份路由协议HSRP:Cisco私有协议 确保了当网络边缘设备或接入链路出现故障时,用户通信能迅速并透明地恢复,以此为ip网络提供余性,通过使用同意虚拟ip地址和虚拟mac地址,LAN网段上的两台或 ...