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 (素数打表 哥德巴赫猜想)
题意: 就是哥德巴赫猜想...任意一个偶数 都可以分解成两个(就是一对啦)质数的加和 输入一个偶数求有几对.. 解析: 首先! 素数打表..因为 质数 + 质数 = 偶数 所以 偶数 - 质数 = 质 ...
随机推荐
- 【Unity】Unity中C#与Android中Java的互相调用遇到的一些问题
1.有关调用的一些问题: (1).在C#中直接调用java中的代码,无返回值: 在java中: public static void setAge(Context context , int leve ...
- AVL树 高度平衡的二叉查找树
1.What is AVL tree? AVL tree 是一种特殊的二叉查找树,,首先我们要在树中引入平衡因子balance,表示结点右子树的高度减去左子树的高度差(右-左),对于一棵AVL树要么它 ...
- kettle连接Hbase中数据导入(8)
http://wiki.pentaho.com/display/BAD/Loading+Data+into+HBase 1)下载样本文件 到官网去下载
- BJFU 1440 fudq的ACM
矩阵快速幂 #include<cstdio> #include<algorithm> using namespace std; ; const int INF =1e9; ; ...
- 基于python的tagcloud
setp1: 安装jieba,pytagcloud pip install jieba apt-get install python-pygame pip install simplejson pip ...
- touchesBegan: withEvent: <--- with UIScrollView / UIImageView
touchesBegan: withEvent: / touchesMoved: withEvent: / touchesEnded: withEvent: 等只能被UIView捕获(如有问题请指出对 ...
- Oracle字符串操作[转:http://www.cnblogs.com/xd502djj/archive/2010/08/11/1797577.html]
ORACLE 字符串操作 1 字符串连接 SQL> select 'abc' || 'def' from dual; 'ABC'|------abcdef 2 小写SQL>select ...
- mipi 调试经验(转)
以下是最近几个月在调试 MIPI DSI / CSI 的一些经验总结,因为协议有专门的文档,所以这里就记录一些常用知识点: 一.D-PHY 1.传输模式 LP(Low-Power) 模式:用于传输控制 ...
- 《TCP/IP详解》读书笔记
本书以UNIX为背景,紧贴实际介绍了数据链层.网络层.运输层 一.整体概念 1.各层协议的关系,只讨论四层 各层常见的协议: 网络层协议:IP协议.ICMP协议.ARP协议.RARP协议. ...
- ShellExecute, WinExec, CreateProcess区别
ShellExecute ShellExecute的功能是运行一个外部程序(或者是打开一个已注册的文件.打开一个目录.打印一个文件等等),并对外部程序有一定的控制. 有几个API函数都可以实现这些功能 ...