2011年浙大:Twin Prime Conjecture
Twin Prime Conjecture
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2659 Accepted Submission(s): 906
Now given any positive integer N (< 10^5), you are supposed to count the number of twin primes which are no greater than N.
The input file consists of several test cases. Each case occupies a line which contains one integer N. The input is finished by a negative N.
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN=;
bool isPrime[MAXN];
int cnt[MAXN];
int main()
{
int n;
memset(isPrime,true,sizeof(isPrime));
for(int i=;i<MAXN;i++)
{
if(isPrime[i])
{
for(int j=i+i;j<MAXN;j+=i)
isPrime[j]=false;
}
}
cnt[]=;
int pre=;
int num=;
for(int i=;i<MAXN;i++)
{
if(isPrime[i])
{
if(i-pre==)
{
num++;
}
pre=i;
}
cnt[i]=num;
}
while(scanf("%d",&n)!=EOF&&n>=)
{
printf("%d\n",cnt[n]);
}
return ;
}
2011年浙大:Twin Prime Conjecture的更多相关文章
- Twin Prime Conjecture(浙大计算机研究生保研复试上机考试-2011年)
Twin Prime Conjecture Time Limit: 2000/1000 MS (Java/Othe ...
- hdu 3792 Twin Prime Conjecture 前缀和+欧拉打表
Twin Prime Conjecture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU3792---Twin Prime Conjecture(树状数组)
Twin Prime Conjecture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 2011年浙大:Graduate Admission
题目描述: It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 app ...
- zoj 4099 Extended Twin Composite Number
Do you know the twin prime conjecture? Two primes and are called twin primes if . The twin prime c ...
- HDU 3792 素数打表
Description If we define dn as: dn = pn+1-pn, where pi is the i-th prime. It is easy to see that d1 ...
- HDU_3792_(素数筛+树状数组)
Twin Prime Conjecture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 2019/11/02 TZOJ
1001 ShaoLin http://www.tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=6003 标记一下i ...
- UVA 10395 素数筛
Twin Primes Twin primes are pairs of primes of the form (p; p + 2). The term \twin prime" was c ...
随机推荐
- C# 托管
委托 委托让我们可以把函数引用保存在变量中.这就像在 C++ 中使用 typedef 保存函数指针一样. 委托使用关键字 delegate 声明.看看这个例子,你就能理解什么是委托: 例子: 代码: ...
- 利用GROUP_CONCAT函数把相同信息的合并到同一个字段中
SELECT a.*,GROUP_CONCAT(b.pri_name) FROM sh_role a LEFT JOIN sh_privilege b ON FIND_IN_SET(b.id,a.pr ...
- Thymeleaf框架
简单说, Thymeleaf 是一个跟 Velocity.FreeMarker 类似的模板引擎,它可以完全替代 JSP .相较与其他的模板引擎,它有如下三个极吸引人的特点: 1.Thymeleaf 在 ...
- /usr/bin/mysqld_safe_helper: Cannot change uid/gid (errno: 1) (转)
From: https://www.rootusers.com/how-to-fix-mariadb-10-0-29-selinux-update-failure/ 安装mysql 10.0.29后, ...
- String代码示例
package lianxi; public class lianxi0112 { public static void main(String[] args) { // TODO 自动生成的方法存根 ...
- PHP购物车模块的实现(php/ajax/session)
购物车网页代码 1.登录界面login.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...
- Hibernate性能优化
1.性能是与具体的项目挂钩的,并不是对于A项目某种优化方法好就适用于B项目.性能需要不断的测试检验出来的.....(废话) 2.session.clear()方法的使用,通常session是有缓存的 ...
- ABAP-创建货源清单
CALL FUNCTION 'ME_DIRECT_INPUT_SOURCE_LIST' *&-------------------------------------------------- ...
- ABAP screen
Instance One : SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-100. SELECTION-SCREEN BEGIN ...
- 扫盲-wpf依赖属性
一.什么是依赖属性 依赖属性就是一种自己可以没有值,并且可以通过绑定从其他数据源获取值.依赖属性可支持WPF中的样式设置.数据绑定.继承.动画及默认值. 将所有的属性都设置为依赖属性并不总是正确的解决 ...