#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;
typedef long long i64;
#define out64 "%lld\n"
#define in64 "%lld"
/************ for topcoder by zz1215 *******************/
#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)
#define FFF(i,a) for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)
#define S64(a) scanf(in64,&a)
#define SS(a) scanf("%d",&a)
#define LL(a) ((a)<<1)
#define RR(a) (((a)<<1)+1)
#define pb push_back
#define CL(Q) while(!Q.empty())Q.pop()
#define MM(name,what) memset(name,what,sizeof(name))
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
// i64 gcd(i64 a,i64 b){return b?gcd(b,a%b):a;}
i64 gcd(i64 _a, i64 _b)
{
if (!_a || !_b)
{
return max(_a, _b);
}
i64 _t;
while ((_t = _a % _b))
{
_a = _b;
_b = _t;
}
return _b;
}
i64 ext_gcd (i64 _a, i64 _b, i64 &_x, i64 &_y)
{
if (!_b)
{
_x = 1;
_y = 0;
return _a;
}
i64 _d = ext_gcd (_b, _a % _b, _x, _y);
i64 _t = _x;
_x = _y;
_y = _t - _a / _b * _y;
return _d;
}
i64 invmod (i64 _a, i64 _p)
{
i64 _ans, _y;
ext_gcd (_a, _p, _ans, _y);
_ans < 0 ? _ans += _p : 0;
return _ans;
}
vector<i64>p;
bool is[1003011];
bool vis[1001111];
bool isp(i64 x)
{
i64 temp = sqrt(double(x));
for(i64 i=0;i<p.size();i++)
{
if(!(x%p[i]))
{
return false;
}
if(p[i]>temp)
{
return true;
}
}
return true;
}
bool pp(i64 x)
{
if(x<100000)
{
return is[x];
}
else
{
return isp(x);
}
}
i64 l,r;
int main()
{
p.clear();
p.pb(2);
MM(is,false);
is[2] = true;
for(i64 i=3;i<100000;i++)
{
if(isp(i))
{
is[i]=true;
p.pb(i);
}
}
i64 k;
i64 tmin;
i64 tmax;
i64 tx,ty;
i64 pre;
while(cin>>l>>r)
{
MM(vis,false);
k=0;
tmin = inf;
tmax = 0;
i64 temp;
for(i64 u=0;u<p.size();u++)
{
i64 temp=i64(l/p[u])*p[u];
if(temp<l)
{
temp+=p[u];
}
while(temp<=r)
{
if(temp>99999 || !is[temp])
{
vis[temp-l]=true;
}
temp+=p[u];
}
}
if(l==1)
{
vis[0]=true;
}
for(i64 i=0;i<=r-l;i++)
{
if(!vis[i])
{
if(k>=1)
{
if(i-pre<tmin)
{
tmin = i - pre;
tx = pre+l;
}
if(i-pre>tmax)
{
tmax = i - pre;
ty = pre+l;
}
}
pre = i;
k++;
}
}
if(k>=2)
{
cout<<tx<<","<<tx+tmin<<" are closest, "<<ty<<","<<ty+tmax<<" are most distant."<<endl;
}
else
{
cout<<"There are no adjacent primes."<<endl;
}
}
return 0;
}
分享到:
相关推荐
pku部分题代码,不多,试一下怎么上传文件!
pku1000 pku1000程序 解题报告
pku经典题目解题报告 pku经典题目解题报告
PKU JudgeOnline FAQ 中文版 常见问题解答
pku1664源代码
8数码代码pku1077,300ms(哈希+广度搜索)
ppt word PKU 课件 五星级灰常强大
benchmark (PKU-MMD) for continuous multi-modality 3D human action understanding and cover a wide range of complex human activities with well annotated information. PKU-MMD contains 1076 long video ...
ACM代码 北大pku。 搞ACM的可以参考一下。代码还是挺规范的。有接近150道题目的代码。
PKU 2339 Rock, Scissors, Paper 源代码
有一些代码是pku上的,希望大家看后给我留言,看看我的代码那里有问题??
pku acm 1469 COURSES 代码 二分图的最大匹配的匈牙利算法 解题报告请访问:http://blog.csdn.net/china8848
这是关于PKU上的题目分类 很详细 适合不同水平的童鞋们参考
北京大学pku2317 Questions and answers c++标程 文件名为2371.cpp
我写的解题报告,关于度限制生成树的 网址:http://acm.pku.edu.cn/JudgeOnline/problem?id=1639<br>题目:Picnic Planning 来源:East Central North America 2000
分词训练用的pku训练集,主要是说明相似度计算的样例数据。
PKU的oj分类 可以通过分类进行练习~~~
pku acm 1042 贪心法
pku2482--Stars in Your Window的源程序