POJ 2909
#include<iostream>
#include<stdio.h>
#define M 35000
#include<math.h>
#define N 3800
using namespace std; int prime [N];
void give_list();
int main()
{
//freopen("acm.acm","r",stdin);
int i;
int j;
int num;
int sum;
give_list();
while(cin>>num)
{
sum = ;
if(num == )
break;
for(i = ; ;++ i)
{
for(j = i; ;++ j)
{
if(prime[i] + prime[j] == num)
++ sum;
if(prime[i] + prime[j] > num)
break;
}
if(prime[i] >= num/)
{
break;
} }
cout<<sum<<endl;
}
} void give_list()
{
int i;
int j;
bool prim1[M];
memset(prim1,true,sizeof(bool)*M);
prim1[] = false;
for(i = ; i < sqrt(long double(M))+; i ++)
{
if(prim1[i])
{
j = *i;
while(j < M)
{
prim1[j] = false;
j += i;
}
}
}
j = ;
for(i = ; i < M; i ++)
{
if(prim1[i])
{
prime[j] = i;
++ j;
}
}
}
POJ 2909的更多相关文章
- [暑假集训--数论]poj2909 Goldbach's Conjecture
For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 ...
- poj2909 欧拉素数筛选
刚刚学了一种新的素数筛选法,效率比原先的要高一些,据说当n趋近于无穷大时这个的时间复杂度趋近O(n).本人水平有限,无法证明. 这是道水题,贴代码出来重点是欧拉筛选法.我把原来普通的筛选法贴出来. / ...
- Poj 2662,2909 Goldbach's Conjecture (素数判定)
一.Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
随机推荐
- IPV4/IPV6双协议栈配置案例
拓扑: XRV1配置: =================================================================== hostname XRV1! ipv6 ...
- [leetcode]46. Permutations全排列(给定序列无重复元素)
Given a collection of distinct integers, return all possible permutations. Input: [1,2,3] Output: [ ...
- 激活prompt
1.下载SQLPrompt 2. 断网, 打开注册机,拷贝验证码 2. 点击activate, 拷贝代码
- ubuntu桌面环境安装中文环境
apt install language-pack-zh-hans* language-pack-gnome-zh-hans* language-pack-kde-zh-hans* apt insta ...
- win10系统配置jdk环境不能用%JAVA_HOME% 代替目录
发现以前配好的java环境变量和tomcat环境变量全都清空了,在重新配置的时候总是出现问题,即在cmd命令窗口下,输入java,显示正常,输入java -version 也是显示正常,唯独输入jav ...
- linux就该这么学,第六天了
今天学了第六天了,主要讲计划任务了,,at,命令,单次有效,一次性的,crontd服务(周期性)计划任务,crontab -e创建,编辑计划任务.crontab -l查看计划任务,crontaab - ...
- ABP框架系列之三十五:(MVC-Controllers-MVC控制器)
Introduction ASP.NET Boilerplate is integrated to ASP.NET MVC Controllers via Abp.Web.Mvc nuget pack ...
- tabel表格的dom操作
对table表格的操作比较麻烦,一直字符串的连接会比较麻烦 var nod = cwgk_msg_list.insertRow();//这个是上边获取过的dom元素,一般是tbody的元素,对元素进行 ...
- python之os库
python之os库 os.name 判断现在正在实用的平台,Windows 返回 'nt'; Linux 返回'posix' >>> os.name 'nt' os.getcwd( ...
- Nginx+Tomcat反向代理利用certbot实现https
一.利用Let's Encrypt 免费生成HTTPS证书 1.下载安装certbot(Let's Encrypt ) 2.利用certbot生成证书 3.配置nginx的https证书 安装cerb ...