题意:如果K个相邻素数p1,p2,p3.....pk满足pk-p1=s,称这些素数组成一个距离为s的素数K元组,输入a,b,k,s,输出区间[a,b]内距离为s的素数k元组的个数。

思路:先打到50000素数表,然后暴力求出a,b区间的素数,然后判断。

 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int t;
int a,b,k,s,cnt;
bool vis[];
int f[];
int p[];
void getprime()
{
cnt=;
memset(vis,,sizeof(vis));
vis[]=true;
vis[]=true;
for(int i=; i<=; i++)
{
if(!vis[i])
{
f[cnt++]=i;
for(int j=i*; j<=; j+=i)
{
vis[j]=true;
}
}
}
} int main()
{
getprime();
scanf("%d\n",&t);
while(t--)
{
scanf("%d%d%d%d",&a,&b,&k,&s);
memset(p,,sizeof(p));
int ans=;
int t1=;
for(int i=a; i<=b; i++)
{
if(i<=)
{
if(!vis[i]) p[t1++]=i;
}
else
{
bool flag=true;
for(int j=; j<cnt&&f[j]*f[j]<=i; j++)
{
if(i%f[j]==)
{
flag=false;
break;
}
}
if(flag)
{
p[t1++]=i;
}
}
}
for(int i=; i<t1; i++)
{
if(p[i+k-]-p[i]==s)
{
ans++;
}
}
printf("%d\n",ans);
}
return ;
}

LA 3998 Prime k-tuple的更多相关文章

  1. 3998 - Prime k-tuple

    {p1,..., pk : p1 < p2 <...< pk} is called a prime k -tuple of distance s if p1, p2,..., pk ...

  2. (算法入门经典大赛 优先级队列)LA 3135(之前K说明)

    A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensor da ...

  3. .Uva&LA部分题目代码

    1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...

  4. hdu4935 Prime Tree(2014多校联合第七场)

    首先这是一道dp题,对题意的把握和对状态的处理是解题关键. 题目给出的范围是n在1到1e11之间,由于在裂变过称中左儿子总是父亲节点的一个非平凡约数,容易看出裂变过程只与 素数幂有关,并且显然有素数不 ...

  5. algorithm@ Sieve of Eratosthenes (素数筛选算法) & Related Problem (Return two prime numbers )

    Sieve of Eratosthenes (素数筛选算法) Given a number n, print all primes smaller than or equal to n. It is ...

  6. POJ2739 Sum of Consecutive Prime Numbers(尺取法)

    POJ2739 Sum of Consecutive Prime Numbers 题目大意:给出一个整数,如果有一段连续的素数之和等于该数,即满足要求,求出这种连续的素数的个数 水题:艾氏筛法打表+尺 ...

  7. ZOJ 3707 Calculate Prime S 数论

    思路:容易得到s[n]=s[n-1]+s[n-2],也就是fib数. 求第k小的fib质数的也就是第k个质数数-2,当k>2时. 在就是s[n]/x%m=s[n]%(x*m)/x. 代码如下: ...

  8. Project Euler:Problem 87 Prime power triples

    The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is ...

  9. Java 的 Tuple 元组数据类型

    元组类型,即 Tuple 常在脚本语言中出现,例如 Scala 的 ("Unmi", "china@qq.com", "blahbla"). ...

随机推荐

  1. VS2010+Opencv-2.4.9的配置攻略

    1.下载软件 vs2010入门书籍,免积分下载   http://download.csdn.net/detail/u014112584/7325617 opencv2.4.0版本号和一些样例,免积分 ...

  2. 关于开发环境 git 重新部署

    apps  开发机器 多次因为升级出现无法登陆 下面就重新部署 流程做笔记 1   备份 根目录下的 那一堆shell 和 Cache/data 下的系统配置 2  shell : su www   ...

  3. Building Tomcat7 source step by step---官方文档

    Table of Contents Introduction Download a Java Development Kit (JDK) version 6 Install Apache Ant 1. ...

  4. Extending Robolectric

    Robolectric is a work in progress, and we welcome contributions from the community. We encourage dev ...

  5. QT Windows下生成动态链接库

    目标:需要将一个QT程序生成动态链接库 Windows环境下Qt生成的共享库文件其后缀为dll,可以在程序运行过程中动态加载 新建项目,选择库 选择共享库 建立好项目后生成三个文件,两个.h一个.cp ...

  6. padding and margin.

    padding is the space between the content and the border, whereas margin is the space outside the bor ...

  7. oracle创建实例SID

    用oracle用户登录 输入startx开发可视化界面,打开命令行模式 (如果只有壁纸,没有桌面图标和任务栏,按下 Ctrl + Alt + T 打开命令行) 输入dbca打开配置窗口 最后就各种下一 ...

  8. IDEA SVN1.8 问题解决

    转自 http://blog.jetbrains.com/idea/2013/12/subversion-1-8-and-intellij-idea-13/

  9. post和get的区别?

    1. get是从服务器上获取数据,post是向服务器传送数据.2. get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到.post是通过H ...

  10. C# Dll动态链接库

    新建一个类库. 2     编写一个简单的类库实例,例如:DllTest在默认名为:calss1.cs里编写代码一下是一个简单的:在控制台显示 “你以成功调用了动态连接!”sing System;us ...