就是大区间求素数  参考

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. JUC——并发集合类

    如果要进行多个数据的保存,无疑首选类集(List.Set.Queue.Map),在类集的学习的时候也知道一个概念:许多集合的子类都具有同步与异步的差别,但是如果真的要在多线程之中去使用这些类,是否真的 ...

  2. oracle数据库更改字符集

    在数据迁徙的时候需要使源和目标数据库的字符集.版本等信息统一…… 这里是对一个数据库的设置,需要在两边进行同样的操作. SYS@PROD1> select userenv('language') ...

  3. 微信小程序自定义 tabbar

    一定的需求情况下,无法使用小程序原生的 tabbar 的时候,需要自行实现一个和 tabbar 功能一模一样的自制组件. 查阅了海量的博客和文档之后,亲自踩坑.总结了三种在不使用微信小程序原生 tab ...

  4. MAC node + git + bower 简单安装

    一 node 安装 打开https://nodejs.org/en/ nodejs官网 下载安装文件 双击.pkg 文件 自动安装即可 二 安装git 打开 http://code.google.co ...

  5. Nginx内置的嵌入变量

    Nginx核心模块ngx_http_core_module自带有许多内置嵌入的变量,这些变量方便我们配置和使用nginx,在nginx的配置文件中我们可以以$开头直接使用这些变量,这些变量表示客户端请 ...

  6. 高可用OpenStack(Queen版)集群-7.Neutron控制/网络节点集群

    参考文档: Install-guide:https://docs.openstack.org/install-guide/ OpenStack High Availability Guide:http ...

  7. 记录一次redis故障

    ResponseError: MISCONF Redis is configured to save RDB snapshots, but is currently not able to persi ...

  8. 20162328蔡文琛 week10 大二

    20162328 2017-2018-1 <程序设计与数据结构>第十周学习总结 教材学习内容总结 理解图与有向图.无向图 理解带权图 会应用带权图 理解图的广度优先遍历和深度优先遍历 掌握 ...

  9. Task 6.4 冲刺Two之站立会议9

    今天主要对昨天用户提出的意见加以改进,虽然有些不能轻易实现但是仍然查阅了很多资料.因为他目前可以实现实时通信的功能,而我们想要在这个基础上实现临时的视频聊天的功能,但是时间有点紧迫,所以还没有实现.

  10. Class 2 四则运算2的设计思路

    设计思路 1.主函数中有一个大的for循环,用户可以一直随机得到相应题目.在嵌套一个循环,其可以直接确定题目数量:定义两个变量,分别作为四则运算的两个运算数,用随机数函数得到两个数值:再利用随机生成函 ...