Bestcoder round 18---A题(素数筛+素数打表+找三个素数其和==n)
Primes Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12 Accepted Submission(s): 11
9
2
#include <string>
#include <iostream>
#include <cstdio>
#include <math.h>
#include <cstring>
#include <algorithm>
#include <queue> using namespace std; int f[10001]; void sushu()
{
int i, j;
memset(f, 0, sizeof(f));
f[1]=1;
i=2;
while(i<=200)
{
for(j=i*2; j<=10000; j+=i)
{
f[j]=1;
}
i++;
while(f[i]==1)
{
i++;
}
}
} int s[10000], e; int main()
{
int n;
int i, j, k;
int cnt;
sushu();
e=0;
for(i=2; i<=10000; i++)
{
if(f[i]==0)
{
s[e++]=i;
}
}
while(scanf("%d", &n)!=EOF)
{
if(n<6)
{
cout<<'0'<<endl;
continue;
}
cnt=0;
int flag=0;
for(i=0; i<=n; i++)
{
if(s[i]>=n)
break;
for(j=i; j<=n; j++)
{
if( (s[i]+s[j])>=n )
{
flag=1;
break;
}
else
{
int dd=n-s[i]-s[j];
if(f[dd]==0 && dd>=s[i] && dd>=s[j] )
{
cnt++;
} }
}
}
cout<<cnt<<endl;
}
return 0;
}
#include <string>
#include <iostream>
#include <cstdio>
#include <math.h>
#include <cstring>
#include <algorithm>
#include <queue> using namespace std; int f[10001]; void sushu()
{
int i, j;
memset(f, 0, sizeof(f));
f[1]=1;
i=2;
while(i<=200)
{
for(j=i*2; j<=10000; j+=i)
{
f[j]=1;
}
i++;
while(f[i]==1)
{
i++;
}
}
} int s[10000], e; int main()
{
int n;
int i, j, k;
int cnt;
sushu();
e=0;
for(i=2; i<=10000; i++)
{
if(f[i]==0)
{
s[e++]=i;
}
}
while(scanf("%d", &n)!=EOF)
{
if(n<6)
{
cout<<'0'<<endl;
continue;
}
cnt=0;
for(i=0; i<=n; i++)
{ for(j=i; j<=n; j++)
{
for(k=j; k<=n; k++)
{
if((s[i]+s[j]+s[k])==n)
{
cnt++;
}
}
}
}
cout<<cnt<<endl;
}
return 0;
}
Bestcoder round 18---A题(素数筛+素数打表+找三个素数其和==n)的更多相关文章
- BestCoder Round #1 第一题 逃生
// 等了好久,BESTCODER 终于出来了..像咋这样的毕业的人..就是去凑凑热闹// 弱校搞acm真是难,不过还是怪自己不够努力// 第一题是明显的拓扑排序,加了了个字典序限制而已// 用优先队 ...
- BestCoder Round #89 B题---Fxx and game(单调队列)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5945 问题描述 输入描述 输出描述 输入样例 输出样例 题意:中文题,不再赘述: 思路: B ...
- BestCoder Round #1 第二题 项目管理
// 第二题 我记得很久很久很久以前看过这样的题目,忘记是哪的区域赛了 // 记得有人说和节点度数有关,我记不清了,反正当时完全不懂 // 然后我想了想,估计就是更新节点度数有关,YY出来可能只要更新 ...
- BestCoder Round #18(hdu5105)Math Problem(高中数学)
最大值无非就是在两个端点或极值点处取得. 我注意讨论了a=0和b=0,却忽略了极值点可能不在L到R的范围内这一问题.被Hack了. #include<iostream> #include& ...
- ACM学习历程—HDU5269 ZYB loves Xor I(位运算 && dfs && 排序)(BestCoder Round #44 1002题)
Problem Description Memphis loves xor very musch.Now he gets an array A.The length of A is n.Now he ...
- HDU5597/BestCoder Round #66 (div.2) GTW likes function 打表欧拉函数
GTW likes function Memory Limit: 131072/131072 K (Java/Others) 问题描述 现在给出下列两个定义: f(x)=f_{0}(x)=\ ...
- Codeforces Round #493 (Div. 1) B. Roman Digits 打表找规律
题意: 我们在研究罗马数字.罗马数字只有4个字符,I,V,X,L分别代表1,5,10,100.一个罗马数字的值为该数字包含的字符代表数字的和,而与字符的顺序无关.例如XXXV=35,IXI=12. 现 ...
- Help Hanzo (素数筛+区间枚举)
Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000). (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...
- UVALive-3399-Sum of Consecutive Prime Numbers(素数筛,暴力)
原题链接 写个素数筛暴力打表一波就AC了: #include <iostream> using namespace std; const int N = 10001; int i, j, ...
随机推荐
- PAT 甲级 1087 All Roads Lead to Rome(SPFA+DP)
题目链接 All Roads Lead to Rome 题目大意:求符合题意(三关键字)的最短路.并且算出路程最短的路径有几条. 思路:求最短路并不难,SPFA即可,关键是求总路程最短的路径条数. 我 ...
- python3:requests模块-写了一点
使用requests,它的七个主要方法,在这里只讲两个:get.post >>> import requests >>> r=requests.get(" ...
- tomcat启动报异常(一)
异常问题:Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web ...
- 如何快速判断IP是内网还是外网(转)
TCP/IP协议中,专门保留了三个IP地址区域作为私有地址,其地址范围如下: 10.0.0.0/8:10.0.0.0-10.255.255.255 172.16.0.0/12:172.16.0.0-1 ...
- PHP平均小数红包算法
<?php function RandMoney( $money,$num ){ $arr = array();//存放金额 $total_money = 0;//红包总金额 $thisMone ...
- DNS入门(转)
转自:阮一峰的网络日志 作者: 阮一峰 DNS 是互联网核心协议之一.不管是上网浏览,还是编程开发,都需要了解一点它的知识. 本文详细介绍DNS的原理,以及如何运用工具软件观察它的运作.我的目标是,读 ...
- Android自定义控件之基本原理(一)
前言: 在日常的Android开发中会经常和控件打交道,有时Android提供的控件未必能满足业务的需求,这个时候就需要我们实现自定义一些控件,今天先大致了解一下自定义控件的要求和实现的基本原理. 自 ...
- 判断是否是iso8859-1编码
if (null == keyword || keyword.equals("关键字")) keyword = ""; if(keywor ...
- 【程序猿联盟】官网上线啦!coderunity.com
wx_fmt=jpeg" alt="" style="max-width:100%; height:auto!important"> 内容简单介 ...
- Mapreduce实战:序列化与反序列化 int,int[],string[][]
最新一期<中国IT产业发展报告>在2016中国(深圳)IT领袖峰会上正式发布,数字中国联合会常务理事李颖称.中国IT产业完毕了从要素驱动向效率驱动的过渡,眼下正在由效率驱动向创新驱动发展. ...