【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\n",ans);
}
return 0;
}
【LightOJ1259】Goldbach`s Conjecture(数论)的更多相关文章
- LightOJ-1259 Goldbach`s Conjecture 数论 素数筛
题目链接:https://cn.vjudge.net/problem/LightOJ-1259 题意 给一个整数n,问有多少对素数a和b,使得a+b=n 思路 素数筛 埃氏筛O(nloglogn),这 ...
- LightOJ1259 Goldbach`s Conjecture —— 素数表
题目链接:https://vjudge.net/problem/LightOJ-1259 1259 - Goldbach`s Conjecture PDF (English) Statistic ...
- LightOJ1259 Goldbach`s Conjecture
题面 T组询问,每组询问是一个偶数n 验证哥德巴赫猜想 回答n=a+b 且a,b(a<=b)是质数的方案个数 Input Input starts with an integer T (≤ 30 ...
- Goldbach`s Conjecture(LightOJ - 1259)【简单数论】【筛法】
Goldbach`s Conjecture(LightOJ - 1259)[简单数论][筛法] 标签: 入门讲座题解 数论 题目描述 Goldbach's conjecture is one of t ...
- [暑假集训--数论]poj2262 Goldbach's Conjecture
In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in whic ...
- F - Goldbach`s Conjecture kuangbin 基础数论
Goldbach's conjecture is one of the oldest unsolved problems in number theory and in all of mathemat ...
- LightOJ - 1259 - Goldbach`s Conjecture(整数分解定理)
链接: https://vjudge.net/problem/LightOJ-1259 题意: Goldbach's conjecture is one of the oldest unsolved ...
- Goldbach's Conjecture
Goldbach's Conjecture Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- Poj 2262 / OpenJudge 2262 Goldbach's Conjecture
1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...
随机推荐
- docker-compose快速搭建lnmp+redis服务器环境
因为我用的是MacOS 安装docker sudo yum update sudo tee /etc/yum.repos.d/docker.repo <<-'EOF' [dockerrep ...
- vi代码智能提示功能及相关配置
vim是一款支持插件.功能无比强大的编辑器,无论你的系统是linux.unix.mac还是windows,都能够选择他来编辑文件或是进行工程级别 的coding.如果能把vim用好了,不仅编程效率能得 ...
- Java开发API文档资源
<netty> http://netty.io/4.1/api/index.html < Spring FrameWork > 1 http://spring.io/ 2 ...
- 彻底理解 Android 中的阴影
如果我们想创造更好的 Android App,我相信我们需要遵循 Material Design 的设计规范.一般而言,Material Design 是一个包含光线,材质和投影的三维环境.如果我们想 ...
- 枚举enum学习小记
参考文献: [1]C++程序设计语言(特别版), 裘宗燕译, 机械工业出版社 [2]C++ Primer (3rd Ed.), S.B. Lippman and J. Lajoie, 人民邮电出版社 ...
- Python print 输出到控制台 丢数据
import xlrd import sys,time data = xlrd.open_workbook("C:\Users\Administrator\Desktop\\new1.xls ...
- Yii2 灵活加载js、css
Yii2.0对于CSS/js 管理,使用AssetBundle资源包类. 视图如何按需加载CSS/JS ? 资源包定义: backend/assets/AppAsset.PHP <?php na ...
- MySQL的BlackHole引擎在主从架构中的作用
MySQL在5.x系列提供了Blackhole引擎–“黑洞”. 其作用正如其名字一样:任何写入到此引擎的数据均会被丢弃掉, 不做实际存储:Select语句的内容永远是空. 和Linux中的 /dev/ ...
- React Native填坑之旅 -- FlatList
在React Native里有很多种方法来创建可滚动的list.比如,ScrollView和ListView.他们都各有优缺点.但是在React Native 0.43里增加了两种行的list vie ...
- clearstatcache
clearstatcache clearstatcache — 清除文件状态缓存 void clearstatcache ([ bool $clear_realpath_cache = false [ ...