题意:判断ll-rr范围内的质数。

一个个用miller-rabin算法判断

//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
using namespace std;
typedef long long lon;
const lon SZ=,INF=0x7FFFFFFF; lon pow(lon x,lon n,lon mod)
{
lon res=,ele=x;
for(;n;)
{
if(n&)res=ele*res%mod;
ele=ele*ele%mod;
n/=;
}
return res;
} bool isp(lon x)
{
if(x==)return ;
int sz=;
lon arr[sz]={,,};
for(lon i=;i<sz;++i)
{
if(x==arr[i])return ;
lon id=x-;
for(;!(id&)&&id;id/=);
lon m=pow(arr[i],id,x);
if(m==)continue;
for(;id!=x-&&m!=;)
{
//if(x==5)cout<<m<<endl;
if(m==x-)break;
m=m*m%x;
//if(m!=1&&m!=x-1)return 0;
id*=;
}
if(m!=x-)return ;
}
return ;
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","w",stdout);
lon casenum;
cin>>casenum;
for(lon time=;time<=casenum;++time)
//for(;scanf("%d",&n)!=EOF;)
{
lon ll,rr;
cin>>ll>>rr;
for(lon i=ll;i<=rr;++i)
{
if(isp(i))cout<<i<<endl;
}
cout<<endl;
}
return ;
}

spoj Prime Generator的更多相关文章

  1. 素数筛法--SPOJ Problem 2 Prime Generator

    质数(prime number)又称素数,除了1和它本身外,不能整除以其他自然数,换句话说就是该数除了1和它本身以外不再有其他的因数:否则称为合数.最小的质数是2. 要判断一个整数N是不是质数很简单, ...

  2. Spoj PRIME1 - Prime Generator

    题意翻译 求给定的两个数之间的素数 Translated by @kaiming 题目描述 Peter wants to generate some prime numbers for his cry ...

  3. SPOJ #2 Prime Generator

    My first idea was Sieve of Eratosthenes, too. But obviously my coding was not optimal and it exceede ...

  4. SPOJ PRIME1 - Prime Generator(线性筛)

    Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate ...

  5. SPOJ Prime or Not - 快速乘 - 快速幂

    Given the number, you are to answer the question: "Is it prime?" Solutions to this problem ...

  6. Prime Generator

    Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate ...

  7. Java 7 Concurrency Cookbook 翻译 第一章 线程管理之二

    三.中断一个线程 一个拥有多个线程的Java程序要结束,需要满足两个条件之一:一是所有的非后台线程都执行结束了:二是某个线程执行了 System.exit() 方法.当你想要终结一个运行中的Java程 ...

  8. JavaScript 性能优化 --By Google V8 Team Manager

    原文:https://developers.google.com/v8/?hl=zh-CN Be Prepared before writing code[9:35] Understand how V ...

  9. 在 SUSE 11 sp2 上安装 freeradius

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...

随机推荐

  1. ACM题目————中位数

    题目描述 长为L的升序序列S,S[L / 2]为其中位数. 给出两个等长升序序列S1和S2,求两序列合并并排序后的中位数. 输入 多组数据,每组第一行为n,表示两个等长升序序列的长度. 接下来n行为升 ...

  2. java网络基础知识的简述

    TCP/UDP的介绍 TCP协议:面向连接的,字节流无差错地传输协议. UDP协议:一个不可靠的无连接的数据传输协议. 说明:TCP可以想象成电话通讯,双方在通话时必须建立连接,一方没听清,会要求对方 ...

  3. Python3.x(windows系统)安装requests库

    Python3.x(windows系统)安装requests库 cmd命令: pip install requests 执行结果:

  4. 2018-2019-1 20189218《Linux内核原理与分析》第七周作业

    task_struck数据结构 在Linux内核中,通过task_struct这个结构体对进程进行管理,我们可以叫他PCB或者进程描述符.这个结构体定义在include/linux/sched.h中. ...

  5. tcp网络通信的三次握手与三次挥手

    背景描述 通过上一篇中网络模型中的IP层的介绍,我们知道网络层,可以实现两个主机之间的通信.但是这并不具体,因为,真正进行通信的实体是在主机中的进程,是一个主机中的一个进程与另外一个主机中的一个进程在 ...

  6. PyCharm/IDEA 使用技巧总结

    基本概念 IDEA 没有类似 Eclipse 的工作空间的概念(workspace),最大单元就是 Project.这里可以把 Project 理解为 Eclipse 中的 workspace.Mod ...

  7. 51NOD 1133 不重叠的线段

    1133 不重叠的线段   X轴上有N条线段,每条线段有1个起点S和终点E.最多能够选出多少条互不重叠的线段.(注:起点或终点重叠,不算重叠).   例如:[1 5][2 3][3 6],可以选[2 ...

  8. C++ 清空队列(queue)的几种方法

    C++中的queue自身是不支持clear操作的,但是双端队列deque是支持clear操作的. 方法一 直接用空的队列对象赋值 queue<int> q1; // process // ...

  9. div滚动条时div内容显示一半

    本文为博主原创,未经允许不得转载 今天在做页面浏览器适配时,将页面中的一个div进行放大时,出现了滚动条,但滚动条对应div中的 内容只能显示一半. 仔细对应属性样式时,div具有overflow:h ...

  10. Leetcode[1]Two Sum C++

    最简单的思想,遍历, 1.两层循环,自己写的,没有用STL,时间花费较长 vector<int> twoSum(vector<int>& nums, int targe ...