HDU 1397 Goldbach's Conjecture【素数打表】
题意:给出n,问满足a+b=n且a,b都为素数的有多少对
将素数打表,再枚举
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
int isp[]; void isprime(){
isp[]=isp[]=;
for(int i=;i<;i++){
if(isp[i]==)
for(int j=i*;j<;j+=i)
isp[j]=;
}
} int main()
{
isprime();
int n,i,j,ans;
while(scanf("%d",&n)!=EOF&&n){
ans=;
for(i=;i<=n/;i++){
if((!isp[i])&&(!isp[n-i])) ans++;
}
printf("%d\n",ans);
}
return ;
}
因为前两天做的一个cf的A就要用到判断素数= =完全忘记该怎么写---555555
HDU 1397 Goldbach's Conjecture【素数打表】的更多相关文章
- LightOJ 1259 Goldbach`s Conjecture 素数打表
题目大意:求讲一个整数n分解为两个素数的方案数. 题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bo ...
- HDU 1397 Goldbach's Conjecture(二分,查找素数)
题目意思很简单,就是找n=p1+p2的种类数,具体看题目吧. 次重点是查找一定范围内的素数: 重点是用二分查找,不然会超时!!! #include<stdio.h> #include< ...
- HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)
Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there e ...
- 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]范围内的偶数,要你将它表示 ...
- Goldbach`s Conjecture LightOJ - 1259 (素数打表 哥德巴赫猜想)
题意: 就是哥德巴赫猜想...任意一个偶数 都可以分解成两个(就是一对啦)质数的加和 输入一个偶数求有几对.. 解析: 首先! 素数打表..因为 质数 + 质数 = 偶数 所以 偶数 - 质数 = 质 ...
- HDU——1397Goldbach's Conjecture(二分查找+素数打表)
Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- hdu 5104 素数打表水题
http://acm.hdu.edu.cn/showproblem.php?pid=5104 找元组数量,满足p1<=p2<=p3且p1+p2+p3=n且都是素数 不用素数打表都能过,数据 ...
随机推荐
- [原创] zabbix学习之旅六:如何解决zabbix server在内网,而邮件发送服务器在外网的问题
通过前面的文章,你已经可以快速地搭建一个报警系统,并能正常的收到报警邮件了.不过在很多企业级环境下,邮件发送服务器往往放在外网,而zabbix server放置在内网,在这种情况下,zabbix的报警 ...
- netbeans设置字体
选择 monospaced 字体 摘抄自:http://blog.sina.com.cn/s/blog_4b6047bc01000boz.html 今天看该文档时,突然意识到通过修改JRE的字体配置文 ...
- JAVA里的String、Timestamp、Date相互转换(转)
转自:http://blog.sina.com.cn/s/blog_6675493d0100lbfl.html Timestamp转化为String: SimpleDateFormat df = ne ...
- Wmware Center安装过程记录
前几天在服务器中安装了Vmware Esxi,以及在客户端中安装了Vmware Client,因此希望能够装一下Vmware vCenter Server试验一下,结果并不顺利,在此记录. 从官网 ...
- WCF 之 OperationContract
这里主要说的是同名异常: [ServiceContract] public interface IUserInfo { [OperationContract] string ShowName(stri ...
- 【转载】C++针对ini配置文件读写大全
http://blog.csdn.net/hgy413/article/details/6666374# ini文件(Initialization file),这种类型的文件中通常存放的是一个程序的初 ...
- Machine Learning Done Wrong
Machine Learning Done Wrong Statistical modeling is a lot like engineering. In engineering, there ar ...
- 物理地址 = 段地址*10H + 偏移地址
程序如何执行: CPU先找到程序在内存中的入口地址 -- 地址总线 (8086有20根地址总线,每一根可以某一时传0或1, 20位的二进制数字可以表示的不同的数字的个数是2^20=1048576 10 ...
- Oracle 学习笔记(三)
1.插入有日期的表,使用 to_date 函数 to_date('1992-12-07', 'yyyy-mm-dd'); 2.使用update更新语句的时候,既可以使用表达式或者数值直接修改数据,也可 ...
- CLR 读书笔记
http://www.cnblogs.com/wang_yb/tag/CLR%20via%20C%23%E7%AC%94%E8%AE%B0/