题意:判断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. python getatime() 查看文件的访问时间

    import time,os def main(): file_name=r'C:\Temp\Req.xml' file_times_access=time.localtime(os.path.get ...

  2. 深入浅出JVM

    这篇文章简要解析了JVM的内部结构.下面这幅图展示了一个典型的JVM(符合JVM Specification Java SE 7 Edition)所具备的关键内部组件. 上图展示的所有这些组件都将在下 ...

  3. Mysql 更改编码方式

    Mysql 更改编码方式 --查看编码方式 show variables like 'char%'; --设置编码方式 set character_set_server=utf8;

  4. JS中怎么调用<%%>的值

    JS中怎么调用<%%>的值 示例代码一: <% String usercode = request.getParameter("usercode");//用req ...

  5. Unable to load the Wrapper's native library because none of the following files及解决方法

    在有几个应用中,在启动的时候发现下列警告: The version of the script (3.5.29) doesn't match the version of this Wrapper ( ...

  6. html/jquery最实用功能与注意点

    获取某元素的父元素 通常用在根据被click的td获取tbody时. parent是指取得一个包含着所有匹配元素的唯一父元素的元素集合.parents则是取得一个包含着所有匹配元素的祖先元素的元素集合 ...

  7. 04: linux基础总结

    目录: 1.1 Red Hat Linux 安装及服务控制 1.2 目录和文件管理 1.3 安装及管理程序 1.4 账号和权限管理 1.5 磁盘和文件管理 1.6 进程和计划任务管理 1.7 Linu ...

  8. windows服务与自启动程序的区别(转载)

    转载:http://blog.csdn.net/anddy926/article/details/8464142 在客户端服务器项目实践中,作为服务端必须保持程序的24小时不间断运行,需要做一个监控, ...

  9. 2016年蓝桥杯B组C/C++省赛(预选赛)题目解析

    2016年蓝桥杯B组C/C++ 点击查看2016年蓝桥杯B组省赛试题(无答案版) 第一题:煤球数目 题解 有一堆煤球,堆成三角棱锥形.具体: 第一层放1个, 第二层3个(排列成三角形), 第三层6个( ...

  10. 【第三十九章】 微服务CICD(1)- gitlab搭建与使用(docker版)

    一.下载docker镜像 前提:docker引擎已经安装好. docker pull gitlab/gitlab-ce gitlab是8.13.1版本. 二.启动应用 docker run -d -h ...