spoj Prime Generator
题意:判断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的更多相关文章
- 素数筛法--SPOJ Problem 2 Prime Generator
质数(prime number)又称素数,除了1和它本身外,不能整除以其他自然数,换句话说就是该数除了1和它本身以外不再有其他的因数:否则称为合数.最小的质数是2. 要判断一个整数N是不是质数很简单, ...
- Spoj PRIME1 - Prime Generator
题意翻译 求给定的两个数之间的素数 Translated by @kaiming 题目描述 Peter wants to generate some prime numbers for his cry ...
- SPOJ #2 Prime Generator
My first idea was Sieve of Eratosthenes, too. But obviously my coding was not optimal and it exceede ...
- SPOJ PRIME1 - Prime Generator(线性筛)
Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate ...
- SPOJ Prime or Not - 快速乘 - 快速幂
Given the number, you are to answer the question: "Is it prime?" Solutions to this problem ...
- Prime Generator
Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate ...
- Java 7 Concurrency Cookbook 翻译 第一章 线程管理之二
三.中断一个线程 一个拥有多个线程的Java程序要结束,需要满足两个条件之一:一是所有的非后台线程都执行结束了:二是某个线程执行了 System.exit() 方法.当你想要终结一个运行中的Java程 ...
- JavaScript 性能优化 --By Google V8 Team Manager
原文:https://developers.google.com/v8/?hl=zh-CN Be Prepared before writing code[9:35] Understand how V ...
- 在 SUSE 11 sp2 上安装 freeradius
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...
随机推荐
- MySQL重装失败,could not start the service MySQL.Error:0
MySQL5.5 安装失败现象: mysqld.exe [6132] 中发生了未经处理的 win32 异常 could not start the service MySQL.Error:0 1.在 ...
- linux基础命令---mswap
mkswap 在Linux设备或者文件中创建交换分区,创建完成之后必须使用swapon来使用它.一般在“/etc/fstab”中有一个交换分区列表,这样开机的时候就可以使用它. 此命令的适用范围:Re ...
- 2016NOI冬令营day5
考试 坑坑坑 无法调试 两个小时写的第一题爆零了 O(n)(n<=200)都能被卡T???数据乱搞吧WOC 10分胸牌滚粗
- python之路----面向对象进阶一
一.isinstance和issubclass isinstance(obj,cls)检查是否obj是否是类 cls 的对象 class Foo(object): pass obj = Foo() i ...
- Django框架介绍之一
这片博文就是对django有个大概的了解,通俗的说,就是先让django跑起来. django安装 在linux上安装如下: 源码安装: tar -zxvf Django-1.9.13.tar.gz ...
- Linux解压文件到指定目录
Linux解压文件到指定目录 tar在Linux上是常用的打包.压缩.加压缩工具,他的参数很多,折里仅仅列举常用的压缩与解压缩参数 参数:-c :create 建立压缩档案的参数:-x : 解压缩压缩 ...
- CSS style 属性
CSS style 属性 定义和用法 必需的 type 属性规定样式表的 MIME 类型. type 属性指示 <style> 与 </style> 标签之间的内容. 值 &q ...
- CSS3实现小黄人动画
转载请注明出处,谢谢! 每次看到CSS3动画就心痒痒想试一下,记得一个多月前看了白树哥哥的一篇博客,突然开窍,于是拿他提供的demo试了一下,感觉很棒!下图为demo提供的动画帧设计稿. 自己也想说搞 ...
- 如何解析读取excel数据
简介 前段时间完成了一个输出excel的任务,感觉挺开心的,用的就是Apache POI的jar包,Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Mic ...
- winform中splitter的用法
1.将winform分为三列 整个窗体分成可以自动调节的三列的做法:1.往窗体上丢两个panel控件其中:panelLeft——设置Dock属性为“left”,并调节好其宽度panelRight——设 ...