题目 POJ2689 Prime Distance

[原题传送门](http://poj.org/problem?id=2689)

主要思路

  • 刚看到这题,心想:不就筛个 \(\left[2,U\right]\) 的质数表出来就可以了吗?一看数据范围: \(1<=L< U<=2147483647\) \(\cdots\) \(Woc\),这 \(TM\) 可以做吗?看来必须另辟蹊径了。于是就有了下面这个做法。

  • 显而易见,一个数 \(x\) 如果不是 \(prime\) ,则在 \(\left[2,\sqrt{x}\right]\) 中必有 \(x\) 的一个质因子。

  • 因为 \(U-L<=1000000\) ,我们可以筛出 \(\left[2,\sqrt{U}\right]\) 的质数表,由这些质数,去将 \(\left[L,U\right]\) 中的合数筛除,那么在 \(\left[L,U\right]\) 中未被标记的便是 \(prime\) 了。

Code:

```cpp
#include
#include
#include
#include
#include
using namespace std;
#define rg register int
#define V inline void
#define I inline int
#define db double
#define B inline bool
#define ll long long
#define F1(i,a,b) for(rg i=a;iV read(TP &x)
{
TP f=1;x=0;register char c=getchar();
for(;c>'9'||c='0'&&cV print(TP x)
{
if(x9) print(x/10);
putchar(x%10+'0');
}
const int N=1000005;
ll L,R;
ll pri[N],cnt,p[N],tot;
bitsetvis;
bool v[N];
templateV make_prime_list(TP n)
{
F1(i,2,n)
{
if(!vis[i]) pri[++cnt]=i;
for(TP j=1;j1) v[j*pri[i]-L]=1;
F1(i,0,R-L)
if(v[i]==0) p[++tot]=i+L;
if(totmaxx) maxx=p[i]-p[i-1],posy=i-1;
if(p[i]-p[i-1]

最新文章

  1. ios - kvo观察者示例
  2. 修改oracle实例名orcl为demo
  3. 关于JAVA的String类的一些方法
  4. ISO9126软件质量模型
  5. opencv保存选择图像中的区域
  6. BroadcastReceiver简单应用实例
  7. Android日历视图(CalendarView)讲解-android学习之旅(三十六)
  8. 高德地图SDK使用经验
  9. Linux禁止ping、开启ping设置
  10. chrome中 GET /undefined 404
  11. tensorflow中的gfile模块(转)
  12. 微软公布针对最新IE漏洞的安全通报2963983
  13. flask第九篇——url_for【2】
  14. js判断软键盘是否开启弹出
  15. 学以致用十八-----shell脚本之基础概念及变量
  16. C# xml通过xslt转换为html输出
  17. sqlserver锁机制详解(sqlserver查看锁)
  18. 【LeetCode 110_二叉树_遍历】Balanced Binary Tree
  19. 常用SQL语句集锦
  20. css文本过长如何设置省略号

热门文章

  1. MQTTnet 3.0.5学习笔记
  2. pytorch中使用多显卡训练以及训练时报错:expect more than 1 value per channel when training, got input size..
  3. Image Processing and Analysis_15_Image Registration:Image matching as a diffusion process: An analogy with Maxwell&#39;s demons——1998
  4. myeclipse 添加反编译插件
  5. Linux shell批量执行scp脚本工具
  6. sql/pl 安装并连接Oracle数据库
  7. C++---初识《通过g++ / makefile 编译和调用动态库so文件》(ubuntu)
  8. tsp问题-遍历算法/随机算法
  9. Oracle查询表空间使用情况的一个sql
  10. PHP获取不到url传递参数中#&amp;等特殊字符解决方法