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 (素数打表 哥德巴赫猜想)
题意: 就是哥德巴赫猜想...任意一个偶数 都可以分解成两个(就是一对啦)质数的加和 输入一个偶数求有几对.. 解析: 首先! 素数打表..因为 质数 + 质数 = 偶数 所以 偶数 - 质数 = 质 ...
随机推荐
- Xcode-App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.
在xcode中上报数据时候,logserver一直没有数据,后来发现控制台有一个提示: 找了半天是因为Xcode7禁止明码的HTTP请求,而自己使用的是Xcode7.2.1 解决办法:修改info.p ...
- c# 方法重载
在c#中同样的方法名称不一样的参数数量和类型可以实现方法重载 class ResultDisplayer{void DisplayResult(string result){// implementa ...
- SSH 两个表全套增删改(运动员住宿管理)
0.创建如下oracle的命令 create table HOTALINFO ( HOTALID ) not null, HOTALNAME ) not null, HOTALADDRESS ) no ...
- 转:Delphi中destroy, free, freeAndNil, release用法和区别
http://blog.sina.com.cn/s/blog_44fa172f0101cur1.html 1)destroy:虚方法 释放内存,在Tobject中声明为virtual,通常是在其子类中 ...
- webapi中的Route的标签的命名参数name的使用
Route Names In Web API, every route has a name. Route names are useful for generating links, so that ...
- Arch声卡配置
ALSA Utilities Install the alsa-utils package. This contains (among other utilities) the alsamixer a ...
- Arch下载官方镜像列表Official mirrors
Official mirrors The official Arch Linux mirror list is available from the pacman-mirrorlist package ...
- 手动编译生成apk
转载一篇介绍如何去手动编译生成apk的文章: http://jojol-zhou.iteye.com/blog/729254
- css格式布局
一.position:fixed 锁定位置(相对于浏览器的位置),例如有些网站的右下角的弹出窗口. 示例 : 二.position:absolute 1.外层没有position:absolute(或 ...
- windows service and process 的关系
1.查询windows 对应的服务 sc query > 1.txt notepad 1.txt 2.查询对应的进程信息 tasklist /m > tasks.txt notepad t ...