LightOJ 1259 Goldbach`s Conjecture 素数打表
题目大意:求讲一个整数n分解为两个素数的方案数。
题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bool类型可以节约不少内存。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stdio.h>
#include<queue>
#include<math.h>
#define INF 0x3f3f3f3f
#define MAX 10000005
#define Temp 10000005 using namespace std; int p[],cnt=;
bool vis[MAX]; void GetPrime()//素数打表
{
memset(vis,false,sizeof(vis));
memset(p,,sizeof(p));
for(int i=;i<MAX;i++)
{
if(!vis[i])
{
p[++cnt]=i;
for(int j=i+i;j<MAX;j+=i)
{
vis[j]=true;
}
}
}
} int main()
{
GetPrime();
int n,T,sum,cns=;
scanf("%d",&T);
while(T--)
{
sum=;
scanf("%d",&n);
for(int i=;p[i]<=n/;i++)//遍历寻找方案数
{
if(vis[n-p[i]]==false)
sum++;
}
printf("Case %d: %d\n",++cns,sum);
}
return ;
}
LightOJ 1259 Goldbach`s Conjecture 素数打表的更多相关文章
- LightOJ - 1259 - Goldbach`s Conjecture(整数分解定理)
链接: https://vjudge.net/problem/LightOJ-1259 题意: Goldbach's conjecture is one of the oldest unsolved ...
- LightOJ 1259 Goldbach`s Conjecture (哥德巴赫猜想 + 素数筛选法)
http://lightoj.com/volume_showproblem.php?problem=1259 题目大意:给你一个数n,这个数能分成两个素数a.b,n = a + b且a<=b,问 ...
- LightOJ 1259 Goldbach`s Conjecture 水题
不想说了 #include <cstdio> #include <iostream> #include <ctime> #include <vector> ...
- POJ 2262 Goldbach's Conjecture (打表)
题目链接: https://cn.vjudge.net/problem/POJ-2262 题目描述: In 1742, Christian Goldbach, a German amateur mat ...
- poj 2262 Goldbach's Conjecture(素数筛选法)
http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total ...
- POJ 2262 Goldbach's Conjecture(素数相关)
POJ 2262 Goldbach's Conjecture(素数相关) http://poj.org/problem?id=2262 题意: 给你一个[6,1000000]范围内的偶数,要你将它表示 ...
- Light oj-1259 - Goldbach`s Conjecture
1259 - Goldbach`s Co ...
- LightOJ1259 Goldbach`s Conjecture —— 素数表
题目链接:https://vjudge.net/problem/LightOJ-1259 1259 - Goldbach`s Conjecture PDF (English) Statistic ...
- Goldbach`s Conjecture LightOJ - 1259 (素数打表 哥德巴赫猜想)
题意: 就是哥德巴赫猜想...任意一个偶数 都可以分解成两个(就是一对啦)质数的加和 输入一个偶数求有几对.. 解析: 首先! 素数打表..因为 质数 + 质数 = 偶数 所以 偶数 - 质数 = 质 ...
随机推荐
- 安卓请求服务器js文件下载到本地,版本号就下载
<?phpreturn array('CJ_V' => 'v0.15',) <script src="/js/reserve.js?<?=C('CJ_V')?> ...
- Django中url匹配规则的补充
Django中url匹配规则是在urls.py文件中配置的. 1.关于正则匹配优先级 在url匹配列表中,如果第一条和第二条同时满足匹配规则,则优先匹配第一条. 在url匹配列表中,如果第一条为正则模 ...
- ElasticSearch(5)-Mapping
一.Mapping概述 映射 为了能够把日期字段处理成日期,把数字字段处理成数字,把字符串字段处理成全文本(Full-text)或精确的字符串值,Elasticsearch需要知道每个字段里面都包含了 ...
- velocity的宏
velocity中的宏macro的使用当中,由于velocity会将宏加载到tomcat中去,但是如果修改之后再加载的话velocity发现有了相同的宏名称,则不会加载 所以这时候的问题就是,在页面上 ...
- matlab显示原图和灰度直方图
**只会显示灰度直方图I = imread('*.bmp') %图必须是灰度图,或者转换为灰度图I=rgb2gray(I);imshow(I);imhist(I); **同时出现在一个平面上I = i ...
- css实现多行超出显示省略号?
可以实现,但是用的是-webkit-私有属性.我用js已经解决了.代码如下:text-overflow: -o-ellipsis-lastline;overflow: hidden;text-over ...
- jquery倒计时过几秒页面跳转 js倒计时
//银行认证成功跳转 var time=setInterval (showTime, 1000); var second=5; function showTime() { if(second==0) ...
- Webdriver如何解决页面元素过期:org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
当运行Webdriver时抛出如下异常:org.openqa.selenium.StaleElementReferenceException: Element not found in the cac ...
- PMP培训感想
终于等到了C打头的邮件,等了几个星期,悬着的心终于放了.1P4M,基本跟平时模块成绩一致.当初模考时,第一次考了126,还算比较满意,毕竟还没开始苦逼看嘛,悲剧的是不管后面再怎么努力,成绩始终在1 ...
- HDU2202--最大三角形(凸包,枚举)
Problem Description 老师在计算几何这门课上给Eddy布置了一道题目,题目是这样的:给定二维的平面上n个不同的点,要求在这些点里寻找三个点,使他们构成的三角形拥有的面积最大.Eddy ...