题目大意:求讲一个整数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 素数打表的更多相关文章

  1. LightOJ - 1259 - Goldbach`s Conjecture(整数分解定理)

    链接: https://vjudge.net/problem/LightOJ-1259 题意: Goldbach's conjecture is one of the oldest unsolved ...

  2. LightOJ 1259 Goldbach`s Conjecture (哥德巴赫猜想 + 素数筛选法)

    http://lightoj.com/volume_showproblem.php?problem=1259 题目大意:给你一个数n,这个数能分成两个素数a.b,n = a + b且a<=b,问 ...

  3. LightOJ 1259 Goldbach`s Conjecture 水题

    不想说了 #include <cstdio> #include <iostream> #include <ctime> #include <vector> ...

  4. POJ 2262 Goldbach's Conjecture (打表)

    题目链接: https://cn.vjudge.net/problem/POJ-2262 题目描述: In 1742, Christian Goldbach, a German amateur mat ...

  5. poj 2262 Goldbach's Conjecture(素数筛选法)

    http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total ...

  6. POJ 2262 Goldbach&#39;s Conjecture(素数相关)

    POJ 2262 Goldbach's Conjecture(素数相关) http://poj.org/problem?id=2262 题意: 给你一个[6,1000000]范围内的偶数,要你将它表示 ...

  7. Light oj-1259 - Goldbach`s Conjecture

                                                                                    1259 - Goldbach`s Co ...

  8. LightOJ1259 Goldbach`s Conjecture —— 素数表

    题目链接:https://vjudge.net/problem/LightOJ-1259 1259 - Goldbach`s Conjecture    PDF (English) Statistic ...

  9. Goldbach`s Conjecture LightOJ - 1259 (素数打表 哥德巴赫猜想)

    题意: 就是哥德巴赫猜想...任意一个偶数 都可以分解成两个(就是一对啦)质数的加和 输入一个偶数求有几对.. 解析: 首先! 素数打表..因为 质数 + 质数 = 偶数 所以 偶数 - 质数 = 质 ...

随机推荐

  1. BitSort

    这个题为<编程珠玑>中提到的算法,解题思路和桶排序/基数排序一样,适用于大量没有重复的数据. 结题思路: 1.遍历整个数据文件,每提取一个数据,在BitMap中对应的位置赋1 2.遍历Bi ...

  2. 一行一行分析JQ源码学习笔记-02

    1.防止冲突    设置新变量保存

  3. Testing a Redux & React web application

    Part 1 - https://www.youtube.com/watch?v=iVKPbH3qyW0 Part 2 - https://www.youtube.com/watch?v=M5lwOs ...

  4. ajax不进success,

    $.ajax({ url:"/order/pay_order_wx?order_id="+order_id, type:'GET', data:"{}", da ...

  5. jquery收集--php收集所有post数据

    $model = D('Account'); $data = $model->create(); jquery收集数据  sendinvite.serialize() function init ...

  6. poj 1142 Smith Numbers

    Description While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh U ...

  7. 小心DLL链接静态库时的内存错误

    本文转自http://www.bennychen.cn/2010/09/%E5%B0%8F%E5%BF%83dll%E9%93%BE%E6%8E%A5%E9%9D%99%E6%80%81%E5%BA% ...

  8. 1.编写TextRw.java的Java应用程序,程序完成的功能是:首先向TextRw.txt中写入自己的学号和姓名,读取TextRw.txt中信息并将其显示在屏幕上。

    package zuoye; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; ...

  9. 总结一下C++各个版本之间的功能扩充

    活到老,学到老.   C++ 98 我们学习和教材中常见的. C++ 03 主要是对98版本进行了bug修复. C++ 11 引入的新功能请参见:         http://www.cpluspl ...

  10. YaHoo Web优化的14条法则

    Web应用性能优化黄金法则:先优化前端程序(front-end)的性能,因为这是80%或以上的最终用户响应时间的花费所在. 法则1. 减少HTTP请求次数 80%的最终用户响应时间花在前端程序上,而其 ...