【题目大意】

若n是素数,输出“Prime”,否则输出n的最小素因子,(n<=2^54)

【题解】

和bzoj3667差不多,知识这道题没那么坑。

直接上Pollord_Rho和Rabin_Miller就行了。

 /*************
POJ 1811
by chty
2016.11.7
*************/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll INF=1000000000000000000LL;
const ll prime[]={,,,,,,,,};
ll T,minn;
inline ll read()
{
ll x=,f=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-; ch=getchar();}
while(isdigit(ch)) {x=x*+ch-''; ch=getchar();}
return x*f;
}
ll gcd(ll a,ll b) {return !b?a:gcd(b,a%b);}
ll mul(ll x,ll y,ll mod) {return ((x*y-(ll)(((long double)x*y+0.5)/mod)*mod)%mod+mod)%mod;}
ll fast(ll a,ll b,ll mod) {ll sum=;for(;b;b>>=,a=mul(a,a,mod))if(b&)sum=mul(sum,a,mod);return sum;}
bool Rabin_Miller(ll p,ll a)
{
if(p==) return ;
if(!(p&)||p==) return ;
ll d=p-;
while(!(d&)) d>>=;
ll m=fast(a,d,p);
if(m==) return ;
for(;d<p;d<<=,m=mul(m,m,p)) if(m==p-) return ;
return ;
}
bool isprime(ll x)
{
for(ll i=;i<;i++)
{
if(prime[i]==x) return ;
if(!Rabin_Miller(x,prime[i])) return ;
}
return ;
}
void Pollord_Rho(ll x)
{
if(isprime(x)) {minn=min(minn,x); return;}
ll c=;
while()
{
ll x1(),x2(),i(),k();
while()
{
x1=(mul(x1,x1,x)+c)%x;
ll d=gcd(x1>x2?x1-x2:x2-x1,x);
if(d>&&d<x)
{
Pollord_Rho(d);
Pollord_Rho(x/d);
return;
}
if(x1==x2) break;
if(++i==k) x2=x1,k<<=;
}
c++;
}
}
void solve(ll x)
{
if(isprime(x)) {puts("Prime"); return;}
minn=INF;
Pollord_Rho(x);
printf("%lld\n",minn);
}
int main()
{
freopen("cin.in","r",stdin);
freopen("cout.out","w",stdout);
T=read();
while(T--){ll x=read();solve(x);}
return ;
}

【POJ1811】Prime Test的更多相关文章

  1. 【CF912E】Prime Game(meet in the middle)

    [CF912E]Prime Game(meet in the middle) 题面 CF 懒得翻译了. 题解 一眼题. \(meet\ in\ the\ middle\)分别爆算所有可行的两组质数,然 ...

  2. 【POJ1811】【miller_rabin + pollard rho + 快速乘】Prime Test

    Description Given a big integer number, you are required to find out whether it's a prime number. In ...

  3. 【数论】Prime Time UVA - 10200 大素数 Miller Robin 模板

    题意:验证1~10000 的数 n^n+n+41 中素数的个数.每个询问给出a,b  求区间[a,b]中质数出现的比例,保留两位 题解:质数会爆到1e8 所以用miller robin , 另外一个优 ...

  4. 【Poj3126】【BNUOJ3245】Prime Path

    http://poj.org/problem?id=3126 https://www.bnuoj.com/v3/problem_show.php?pid=3245 题目鬼图 刚开始看到题目的图觉得这题 ...

  5. 【XSY2719】prime 莫比乌斯反演

    题目描述 设\(f(i)\)为\(i\)的不同的质因子个数,求\(\sum_{i=1}^n2^{f(i)}\) \(n\leq{10}^{12}\) 题解 考虑\(2^{f(i)}\)的意义:有\(f ...

  6. 【UVA10140】Prime Distance

    题目大意:求出一个给定区间 [l, r] 内相邻素数之间的最大距离和最小距离. 题解:由于 l, r 的范围太大,没法直接用筛法得出区间的素数.考虑筛出区间的素数等价于筛掉区间内的所有和数, 根据算术 ...

  7. 【搜索】 Prime Path

    #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include& ...

  8. 【CodeChef】Prime Distance On Tree

    vjudge 给定一棵边长都是\(1\)的树,求有多少条路径长度为质数 树上路径自然是点分治去搞,但是发现要求是长度为质数,总不能对每一个质数都判断一遍吧 自然是不行的,这个东西显然是一个卷积,我们合 ...

  9. 【arc080F】Prime Flip

    Portal --> arc080_f Solution ​  这题的话..差分套路题(算吗?反正就是想到差分就很好想了qwq) ​​  (但是问题就是我不会这种套路啊qwq题解原话是:&quo ...

随机推荐

  1. caddy server 了解

    Caddy 是一个Go写的服务器软件,官方的宣传语“The HTTP/2 web server with automatic HTTPS”以及“Serve The Web Like It's 2016 ...

  2. Linux环境下安装zookeeper

    1. 下载安装文件zookeeper-3.4.6.tar.gz 镜像地址1: http://apache.fayea.com/zookeeper/ 镜像地址2: http://mirrors.hust ...

  3. (四)、Fiddler打断点

    一.打断点是Fiddler一个比较好用的功能,它可以做一些手工操作很难做的事情. 那为什么要打断点? 看下图,Fiddler打开后,Client(客户端)发送的请求会先经过Fiddler,然后Fidd ...

  4. 关于RedHat Enterprise Linux 6.4使用Centos 6 的yum源

    思路:卸载redhat自带yum,然后下载centos的yum,安装后修改配置文件 1.首先到http://mirrors.163.com/centos下载软件包 x86 地址:http://mirr ...

  5. Data_Structure01-绪论作业

    一.作业题目 仿照三元组或复数的抽象数据类型写出有理数抽象数据类型的描述 (有理数是其分子.分母均为整数且分母不为零的分数). 有理数基本运算: 构造有理数T,元素e1,e2分别被赋以分子.分母值 销 ...

  6. bc显示小数点前的0

    bc是强大而常用的计算工具.不过在除法运算时,如果得到的结果值小于1,得到的小数前面的0不存.本篇提供几个常用小数点前缺0的解决方法. [root@maqing ~]# bc bc Copyright ...

  7. ALSA声卡11_从零编写之调试——学习笔记

    1.调试 (1)把程序拷贝到服务器上进行编译 (2)把程序放到内核上面去 重新配置内核,吧原来的声卡驱动程序去掉 a. 修改语法错误 11th_myalsa b. 配置内核去掉原来的声卡驱动 -> ...

  8. wampserver提示You don't have permission to access

    在wampserver上单击左键,打开菜单中Apache下的httpd.conf 注视掉以下代码  <Directory “C:/wamp/www”> Deny from all Allo ...

  9. django Chinese

    http://usyiyi.cn/translate/django_182/contents.html

  10. C#条形码生成(五)----Web下的测试

    Html部分 <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server" ...