【题解】UVA10140 Prime Distance

哈哈哈哈\(miller-rabbin\)水过去了哈哈哈

还能怎么办呢?\(miller-rabbin\)直接搞。枚举即可,还跑得飞快。

当然此题由于\(20000^2 >2^{31}\),直接预处理\(20000\)内的质数就好了

放mr的代码

#include<bits/stdc++.h>

using namespace std;typedef long long ll;
#define DRP(t,a,b) for(register int t=(a),edd=(b);t>=edd;--t)
#define RP(t,a,b) for(register int t=(a),edd=(b);t<=edd;++t)
#define ERP(t,a) for(register int t=head[a];t;t=e[t].nx)
#define midd register int mid=(l+r)>>1
#define TMP template < class ccf >
#define lef l,mid,pos<<1
#define rgt mid+1,r,pos<<1|1
#define pushup(pos) (seg[pos]=seg[pos<<1]+seg[pos<<1|1])
TMP inline ccf qr(ccf b){
register char c=getchar();register int q=1;register ccf x=0;
while(c<48||c>57)q=c==45?-1:q,c=getchar();
while(c>=48&&c<=57)x=x*10+c-48,c=getchar();
return q==-1?-x:x;}
TMP inline ccf Max(ccf a,ccf b){return a<b?b:a;}
TMP inline ccf Min(ccf a,ccf b){return a<b?a:b;}
TMP inline ccf Max(ccf a,ccf b,ccf c){return Max(a,Max(b,c));}
TMP inline ccf Min(ccf a,ccf b,ccf c){return Min(a,Min(b,c));}
TMP inline ccf READ(ccf* _arr,int _n){RP(t,1,_n)_arr[t]=qr((ccf)1);}
//----------------------template&IO---------------------------
#define int long long
inline int ksm(ll base,ll p,ll mod){register int ret=1;base%=mod;
for(register ll t=p;t;t>>=1,(base*=base)%=mod) if(t&1) (ret*=base)%=mod;
return ret%mod;
} inline bool T(int base,int p){
for(register int t=p-1,sav;t;t>>=1){
sav=ksm(base,t,p);
if(sav!=1&&sav!=p-1) return 0;
if((t&1)||sav==p-1) return 1;
}return 1;
} inline bool mb(int x){
if(x==2||x==3||x==13||x==17) return 1;
if(x==1) return 0;
return T(2,x)&&T(3,x)&&T(13,x)&&T(17,x);
} int L,R,last,Mx,Mn,ans1,ans2,ans3,ans4;
main(){
while(cin>>L>>R){
Mx=0;
Mn=R-L+2;last=R+1;
RP(t,L,R) if(mb(t)){ last=t; break;}
if(last==R+1) {printf("There are no adjacent primes\n"); continue;}
RP(t,last+1,R){
if(mb(t)){
if(t-last>Mx) Mx=t-last,ans3=last,ans4=t;
if(t-last<Mn) Mn=t-last,ans1=last,ans2=t;
last=t;
}
}
if(Mx==0||Mn==R-L+2) printf("There are no adjacent primes.\n");
else printf("%d,%d are closest, %d,%d are most distant.\n",ans1,ans2,ans3,ans4);
}
return 0;
}

【题解】UVA10140 [Prime Distance]的更多相关文章

  1. UVA10140 Prime Distance

    UVA10140 Prime Distance 给定两个整数L,R(1<=L<=R<=2^{31},R-L<=10^6)L,R(1<=L<=R<=231,R− ...

  2. UVA10140 Prime Distance【素数/数论】By cellur925

    题目传送门 我们注意到,L,R是肥肠大的.........我们不可能在1s内筛出2^31内的全部质数. “上帝为你关上一扇门,同时为你打开一扇窗” 我们又注意到,R-L是肥肠比较小的,珂以从这入手解决 ...

  3. poj 2689 Prime Distance(大区间素数)

    题目链接:poj 2689 Prime Distance 题意: 给你一个很大的区间(区间差不超过100w),让你找出这个区间的相邻最大和最小的两对素数 题解: 正向去找这个区间的素数会超时,我们考虑 ...

  4. CodeChef - PRIMEDST Prime Distance On Tree 树分治 + FFT

    Prime Distance On Tree Problem description. You are given a tree. If we select 2 distinct nodes unif ...

  5. 数论 - 素数的运用 --- poj 2689 : Prime Distance

    Prime Distance Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12512   Accepted: 3340 D ...

  6. UVA 10140 - Prime Distance(数论)

    10140 - Prime Distance 题目链接 题意:求[l,r]区间内近期和最远的素数对. 思路:素数打表,打到sqrt(Max)就可以,然后利用大的表去筛素数.因为[l, r]最多100W ...

  7. [POJ268] Prime Distance(素数筛)

    /* * 二次筛素数 * POJ268----Prime Distance(数论,素数筛) */ #include<cstdio> #include<vector> using ...

  8. 一本通1619【例 1】Prime Distance

    1619: [例 1]Prime Distance 题目描述 原题来自:Waterloo local,题面详见 POJ 2689 给定两个整数 L,R,求闭区间 [L,R] 中相邻两个质数差值最小的数 ...

  9. POJ2689 Prime Distance(数论:素数筛选模板)

    题目链接:传送门 题目: Prime Distance Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Des ...

随机推荐

  1. 线程和进程(Java)

    一.线程概述 线程是程序运行的基本执行单元.当操作系统(不包括单线程的操作系统,如微软早期的DOS)在执行一个程序时,会在系统中建立一个进程,而在这个进程中,必须至少建立一个线程(这个线程被称为主线程 ...

  2. 某考试T2 frog

    题目背景 无 题目描述 数轴上有 n 只青蛙,分别编号为 1 到 n.青蛙 i 的初始位置的坐标为 xi. 它们准备进行如下形式的移动:每轮包括 m 次跳跃,第 i 次跳跃由青蛙 ai(1 < ...

  3. TIDB 安装

    https://my.oschina.net/dmdgeeker/blog/718564 SQL 层一直是用 Golang 在开发,存储引擎 TiKV 用的 Rust

  4. delphi中如何将string类型的字符串数据转化成byte[]字节数组类型的数据

    var  S:String;  P:PChar;  B:array of Byte;begin  S:='Hello';  SetLength(B,Length(S)+1);  P:=PChar(S) ...

  5. Android 日期对话框DatePickerDialog

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@ ...

  6. 从Android动画到贝塞尔曲线

    基础知识: 动画通过连续播放一系列画面,给视觉造成连续变化的图画.很通俗的一种解释.也很好理解.那么我们先来一个案例看看. 动画案例:百度贴吧小熊奔跑 效果: topic.gif 代码: <?x ...

  7. Zend Studio 9.0.2破解文件和注册码下载

    Zend Studio是Zend Technologies开发的PHP语言集成开发环境(IDE),是公认最好的PHP开发工具.当前Zend Studio最新版本是9.0.2. Zend Studio ...

  8. C语言对文件的读写操作以及处理CSV文件的方法

    #include <stdio.h> #define F_PATH "d:\myfile\file.txt" int main(void) { FILE *fp = N ...

  9. 使用 ODP.NET 访问 Oracle(.net如何访问Oracle)详解【转】

    http://www.cnblogs.com/qinpengming/archive/2013/06/08/3127346.html 1,什么是ODF .NE,?就是Oracle 为 .NET (OD ...

  10. 如何把VBS转换为EXE文件

    如下所示,我想要做一个把360网速测试剥离开来的绿色版,有一个TestSpeed.bat命令,双击之后去执行了360AppLoader.exe,并且会调用netmon文件夹的NetSpeed.dll文 ...