就是大区间求素数  参考

LightOJ - 1197

https://www.cnblogs.com/WTSRUVF/p/9190660.html

直接套那个代码就好了

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
const int maxn = * 1e9;
int primes[];
bool vis[maxn+];
int ans = ;
vector<int> G; void init()
{
mem(vis,);
vis[] = ;
for(int i=; i<=; i++)
if(!vis[i])
{
primes[ans++] = i;
for(LL j=(LL)i*i; j<=; j+=i)
vis[j] = ;
}
} int main()
{
init();
int T;
int kase = ;
LL a, b, u, s;
cin>> T;
while(T--)
{
G.clear();
int res = ;
mem(vis,);
cin>> a >> b >> u >>s;
// if(a <= 2) a = 2;
int len = b - a;
for(int i=; i<ans && primes[i] * primes[i] <= b; i++)
{
int j = a/primes[i];
if(j*primes[i] < a) j++;
if(j <= ) j++;
while(j*primes[i] <= b)
{
vis[j*primes[i] - a] = ;
j++;
} }
if(a == ) vis[] = ;
for(int k=; k<=len; k++)
if(!vis[k] && a + k > )
G.push_back(a+k);
for(int i=; i + u - <G.size(); i++)
if(G[i+u-] - G[i] == s)
res++;
printf("%d\n",res); } return ;
}

我觉着人家写的代码比较好  参考一下

#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm> using namespace std;
typedef long long ll;
const int sqrt_inf = ;
const int maxn = * 1e9; int np, pri[sqrt_inf];
bool vis[maxn+];
vector<int> vec; void prime_table (int n) {
np = ;
memset(vis, , sizeof(vis)); for (int i = ; i <= n; i++) {
if (vis[i])
continue; pri[np++] = i;
for (int j = i * i; j <= n; j += i)
vis[j] = ;
}
} int solve () {
int ret = ;
int a, b, s, k;
vec.clear();
memset(vis, , sizeof(vis)); scanf("%d%d%d%d", &a, &b, &k, &s); for (int i = ; i < np && pri[i] * pri[i] <= b; i++) {
int u = pri[i], d = (u - a % u) % u; if (u == a + d)
d += u; while (d <= b - a) {
vis[d] = ;
d += u;
}
} for (int i = ; i <= b-a; i++) {
if (vis[i] == && a + i > )
vec.push_back(a+i);
} for (int i = ; i + k - < vec.size(); i++) {
if (vec[i+k-] - vec[i] == s)
ret++;
} return ret;
} int main () {
prime_table(sqrt_inf); int cas;
scanf("%d", &cas); while (cas--) {
printf("%d\n", solve());
}
return ;
}

Prime k-tuple UVA - 1404的更多相关文章

  1. 暴力求解——素环数 Prime Ring Problem ,UVa 524

    Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbers i ...

  2. Again Prime? No Time. UVA - 10780(质因子分解)

    m^k就是让m的每个质因子个数都增加了k倍 求m的质因子 在n!中增加了多少倍就好了,因为m^k 表示每一个质因子增加相同的倍数k  所以我们需要找到增加倍数最小的那个..短板效应  其它质因子多增加 ...

  3. Prime Ring Problem UVA - 524

    A ring is composed of n (even number) circles as shown in diagram. Put natural numbers 1,2,...,n int ...

  4. uva 524(Prime Ring Problem UVA - 524 )

    dfs练习题,我素数打表的时候j=i了,一直没发现实际上是j=i*i,以后可记住了.还有最后一行不能有空格...昏迷了半天 我的代码(紫书上的算法) #include <bits/stdc++. ...

  5. 3998 - Prime k-tuple

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

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

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

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

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

  8. 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 ...

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

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

随机推荐

  1. Vue实例 中的常用配置项

    创建Vue实例时,使用 new Vue ({//配置项}) 或者 组件定义中 export default {//配置项},所有的Vue组件都是Vue实例,并且接受相同的选项对象(一些根实例特有的选项 ...

  2. Python创建虚拟环境

    用于创建和管理虚拟环境的模块称为 venv.venv 通常会安装你可用的最新版本的 Python.如果您的系统上有多个版本的 Python,您可以通过运行 python3 或您想要的任何版本来选择特定 ...

  3. 新特性:postgresql的vacuum漫谈

    文章出处:来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31556440/viewspace-2375109/ 前言 即便是从数据库特性,SQL功能性等方面,Pos ...

  4. 控制台报错: SCRIPT1006: Expected ')'

    今天做网站的时候,jsp页面取一个值死活取不出来. <script> if(${not empty requestScope.article.articleId}){ alert(${re ...

  5. python基础学习笔记(一)

    最好有点c++基础来看,,每天都更新一篇吧 这一篇是一些基础东西 1.运算符2.变量3.基本输入输出4.字符串5.列表6.元组7.字典8.集合9.简单的说下循环啥的 1.运算符 特别的 a / b:为 ...

  6. python编辑选课系统

    一.需求分析 1. 创建北京.上海 2 所学校 2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开 3. 课程包含,周期,价格,通过学校创建课 ...

  7. Codeforces1084 | Round526Div2 | 瞎讲报告

    目录 A. The Fair Nut and Elevator B.Kvass and the Fair Nut C.The Fair Nut and String D.The Fair Nut an ...

  8. react-native ListView 性能问题

    常见性能问题已经有很多答案,这里要说的是使用ListView时注意的地方,    ListView的容器需要设定一个固定高度, 不然ListView中的item过多,会把整体页面撑开,设置的 remo ...

  9. iOS 模块化、组件化方案探索(利用cocoapods 、git 创建私有仓库)

    来自bang's blog http://blog.cnbang.net/tech/3080/ 模块化 简单来说,模块化就是将一个程序按照其功能做拆分,分成相互独立的模块,以便于每个模块只包含与其功能 ...

  10. iOS开发学习-类似微信聊天消息中的电话号码点击保存到通讯录中的功能

    类似微信聊天消息中的电话号码点击保存到通讯录中的功能,ABAddress的实现在iOS9中是不能正常使用的,点击完成后,手机会非常的卡,iOS9之后需要使用Contact新提供的方法来实现该功能.快捷 ...