codeforce --- 237C
2 seconds
256 megabytes
standard input
standard output
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers a, a + 1, ..., b (a ≤ b). You want to find the minimum integer l (1 ≤ l ≤ b - a + 1) such that for any integer x(a ≤ x ≤ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers.
Find and print the required minimum l. If no value l meets the described limitations, print -1.
A single line contains three space-separated integers a, b, k (1 ≤ a, b, k ≤ 106; a ≤ b).
In a single line print a single integer — the required minimum l. If there's no solution, print -1.
2 4 2
3
6 13 1
4
1 4 3
-1
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = ;
#define inf (1<<29)
// p[i] is i-th prime's position
bool pp[maxn];
int p[maxn] , cnt = ;
int ss[maxn] , tt[maxn];
void init() {
cnt = ;
pp[] = pp[] = ;
tt[] = tt[] = -;
for(int i=;i<maxn;i++) {
if(!pp[i]) {
p[cnt++] = i;
for(int j=i+i;j<maxn;j+=i) {
pp[j] = true;
}
}
tt[i] = cnt - ;
}
for(int i=;i<maxn;i++) {
if(!pp[i]) ss[i] = tt[i];
else ss[i] = tt[i] + ;
}
}
int main() {
init();
int a , b , k;
while(~scanf("%d%d%d" , &a,&b,&k)) {
int s = ss[a] , t = tt[b];
int num = t - s + ;
//printf("debug:\n");
//printf("s is %d , t is %d\n" , s , t);
//printf("first pri is %d , last prime is %d\n" , p[s] , p[t]);
if(num < k) {
printf("-1\n");
continue;
}
int ans = ;
int tmp;
tmp = b - p[t-k+] + ;
if(tmp > ans) ans = tmp;
tmp = p[s+k-] - a + ;
if(tmp > ans) ans = tmp;
for(int i=s;i+k<=t;i++) {
tmp = p[i+k] - p[i];
if(tmp > ans) ans = tmp;
}
printf("%d\n" , ans);
}
return ;
}
codeforce --- 237C的更多相关文章
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
- Codeforce Round #216 Div2
e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...
- Codeforce 水题报告(2)
又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...
- codeforce 375_2_b_c
codeforce 375_2 标签: 水题 好久没有打代码,竟然一场比赛两次卡在边界条件上....跪 b.题意很简单...纯模拟就可以了,开始忘记了当字符串结束的时候也要更新两个值,所以就错了 #i ...
- codeforce 367dev2_c dp
codeforce 367dev2_c dp 标签: dp 题意: 你可以通过反转任意字符串,使得所给的所有字符串排列顺序为字典序,每次反转都有一定的代价,问你最小的代价 题解:水水的dp...仔细想 ...
- 三维dp&codeforce 369_2_C
三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...
- 强连通分量&hdu_1269&Codeforce 369D
强连通分量 标签: 图论 算法介绍 还记得割点割边算法吗.回顾一下,tarjan算法,dfs过程中记录当前点的时间戳,并通过它的子节点的low值更新它的low,low值是这个点不通过它的父亲节点最远可 ...
- 【树状数组】区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D
[树状数组]区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D PROBLEM 题目描述 初始给定n个卡片拍成一排,其中第i个卡片上的数为x[i]. 有q个询问,每次询问 ...
- 解题报告:codeforce 7C Line
codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...
随机推荐
- xml--小结③DTD的基本语法(看懂即可)
四.DTD的基本语法(看懂即可)1.DTD:Document Type Definition2.作用:约束XML的书写规范.3.DTD文件保存到磁盘时,必须使用UTF-8编码 4.如何引入外部的DTD ...
- Windows 7 + Visual Studio 2012 + cocos2d-x 2.1.5
下载cocos2d-x google code : http://code.google.com/p/cocos2d-x/downloads/list cocos2d 官网: http://cocos ...
- A题笔记(4)
No. 1384 这题没啥 不过网考成绩出了,发现我的口语分数相较其他人还挺高的~~~哈哈哈 Code::Blocks 有时在程序运行结束后,.exe 并没有结束,因而之后无论怎么调试和修改代码,运行 ...
- .NET(C#):获取进程的内存私有工作集
当前.NET Framework(.NET 4.0)的Process仅提供进程的内存工作集的获取(通过WorkingSet64属性),而没有提供对私有工作集的获取.注意在Windows Vista之后 ...
- 收集SQLServer线程等待信息
要知道线程等待时间是制约SQL Server效率的重要原因,这一个随笔中将学习怎样收集SQL Server中的线程等待时间,类型等信息,这些信息是进行数据库优化的依据. sys.dm_os_wait_ ...
- Orcale安装完成后 em管理、性能无法登陆 报:没有找到主机
先在我的电脑环境变量中加入oracle_sid=orcl 在Orcale主目录中查找emd.properties 文件修改(时间格式) agentTZRegion=GMT agentTZRegion= ...
- MyEclipse中配置自己的JRE和tomcat
MyEclipse中配置自己的JRE:windows>Preference>java>Installed JREs>Add>Stantard VM>next> ...
- dx环境搭建
我使用的是vs2012+DXSDK_Jun10 DXSDK_Jun10下载地址http://download.microsoft.com/download/A/E/7/AE743F1F-632B-48 ...
- 利用jquery进行ajax提交表单和附带的数据
1.获取表单数据: $form.serialize() 2.附带数据:input[status]=1 3.构造url链接:url = $form.attr('action') + '?input[st ...
- mysql-积累管理sql语句
//连接数据库 mysql -h xxx -u root -p; //查看数据库 show databases //查看数据表 show tables //查看某数据表结构 desc xxx表 //修 ...