传送门

Pollard−rhoPollard-rhoPollard−rho模板题。

题意简述:求ϕ(n),n≤1e18\phi(n),n\le 1e18ϕ(n),n≤1e18

先把nnn用Pollard−rhoPollard-rhoPollard−rho分解质因数,然后就可以算了。

代码:

#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define ri register int
using namespace std;
typedef unsigned int uint;
typedef long long ll;
tr1::unordered_map<ll,int>S;
int pri[10]={2,3,5,7,11,13,17,19,23,29};
vector<ll>fac;
inline uint unit(){
    static uint state0=19491001;
    state0^=(state0>>13);
    state0^=(state0<<17);
    state0^=(state0>>5);
    return state0;
}
inline ll ksc(ll a,ll b,ll mod){return (a*b-(ll)((long double)a/mod*b)*mod+mod)%mod;}
inline ll ksm(ll a,ll p,ll mod){ll ret=1;a%=mod;for(;p;p>>=1,a=ksc(a,a,mod))if(p&1)ret=ksc(ret,a,mod);return ret;}
inline bool check(ll x,ll a,ll s,ll t){
	a=ksm(a,t,x);
	ll p=a;
	if(a==1||a==x-1)return 1;
	while(s--){
		a=ksc(p,p,x);
		if(a==1&&(p!=x-1&&p!=1))return 0;
		p=a;
	}
	return p==1;
}
inline bool MRT(ll x){
	if(x==2||x==3)return fac.push_back(x),1;
	if(!(x&1))return 0;
	if(x%6!=1&&x%6!=5)return 0;
	ll s=0,t=x-1;
	while(!(t&1))t>>=1,++s;
	for(ri i=0;i<10;++i){
		if(x==pri[i])return fac.push_back(x),1;
		if(!(x%pri[i]))return 0;
		if(!check(x,pri[i],s,t))return 0;
	}
	return fac.push_back(x),1;
}
inline ll F(ll x,ll c,ll mod){return (ksc(x,x,mod)+c)%mod;}
inline ll gcd(ll a,ll b){while(b){ll t=a;a=b,b=t%a;}return a;}
inline ll rho(ll n,ll c){
	ll x=unit()%n+1,y=x,p=1;
	for(ri i=1,k=2;p==1;++i){
		x=F(x,c,n),p=gcd(y>x?y-x:x-y,n);
		if(i==k)y=x,k<<=1;
	}
	return p;
}
inline void solve(ll n){
	if(n==1||MRT(n))return;
	ll d=rho(n,unit()%n);
	while(d==n)d=rho(n,unit()%n);
	solve(n/d),solve(d);
}
int main(){
	freopen("lx.in","r",stdin);
	ll n,ans;
	scanf("%lld",&n),solve(n),ans=n;
	for(ri i=fac.size()-1;~i;--i){
		if(S[fac[i]])continue;
		S[fac[i]]=1,ans=ans/fac[i]*(fac[i]-1);
	}
	return cout<<ans,0;
}

2018.12.17 bzoj4802: 欧拉函数(Pollard-rho)的更多相关文章

  1. BZOJ4802 欧拉函数 (Pollard-Rho Miller-Robin)

    题目 求大数的欧拉函数φ\varphiφ 题解 Pollard-Rho 板子 CODE #pragma GCC optimize (3) #include <bits/stdc++.h> ...

  2. bzoj4802 欧拉函数(附Millar-Rabin和Pollard-Rho讲解)

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4802 [题解] 参考:http://www.matrix67.com/blog/archiv ...

  3. BZOJ4802:欧拉函数(Pollard-Rho,欧拉函数)

    Description 已知N,求phi(N) Input 正整数N.N<=10^18 Output 输出phi(N) Sample Input 8 Sample Output 4 Soluti ...

  4. [日常摸鱼]bzoj4802 欧拉函数-PollardRho大整数分解算法

    啊居然要特判,卡了好久QAQ (好像Windows下的rand和Linux下的不一样? QwQ一些东西参考了喵铃的这篇blog:http://www.cnblogs.com/meowww/p/6400 ...

  5. [BZOJ4802]欧拉函数

    bzoj description 给出\(n\),求\(\varphi(n)\).\(n\le10^{18}\) sol \(Pollard\ Rho\),存个代码. code #include< ...

  6. BZOJ4802 欧拉函数 数论

    原文链接http://www.cnblogs.com/zhouzhendong/p/8117744.html 题目传送门 - BZOJ4802 题意概括 Description 已知N,求phi(N) ...

  7. 数学基础IV 欧拉函数 Miller Rabin Pollard's rho 欧拉定理 行列式

    找了一些曾经没提到的算法.这应该是数学基础系最后一篇. 曾经的文章: 数学基础I 莫比乌斯反演I 莫比乌斯反演II 数学基础II 生成函数 数学基础III 博弈论 容斥原理(hidden) 线性基(h ...

  8. 【BZOJ4802】欧拉函数(Pollard_rho)

    [BZOJ4802]欧拉函数(Pollard_rho) 题面 BZOJ 题解 这么大的范围肯定不好杜教筛. 考虑欧拉函数的计算式,显然只需要把\(n\)分解就好了. 直接\(Pollard\_rho\ ...

  9. BZOJ_4802_欧拉函数_MR+pollard rho+欧拉函数

    BZOJ_4802_欧拉函数_MR+pollard rho+欧拉函数 Description 已知N,求phi(N) Input 正整数N.N<=10^18 Output 输出phi(N) Sa ...

随机推荐

  1. HDU-2612.Find way .(不同起点不同终点的BFS)

    我要被这个好用的memset气死了...... 真香 #include <cstring> #include <string> int main () { ]; memset( ...

  2. 像素 转换 px dp

    public static int dip2px(Context context, float dpValue){ final float scale = context.getResources() ...

  3. JS中取得<asp:TextBox中的值

    var s = document.getElementById("<%=txt_DaShen.ClientID %>").value; 注:txt_DaShen 为as ...

  4. 一分钟了解mongodb(转)

    mongo的由来 截取自英文俚语humongous,意为”巨大的”,是否表明mongodb在设计之初就是为大数据量处理而生呢? mongodb是个啥 mongodb是个可扩展.高性能.开源.面向文档( ...

  5. dev-client.js-配合dev-server.js监听html文件改动也能够触发自动刷新

    // 引入 webpack-hot-middleware/client var hotClient = require('webpack-hot-middleware/client'); // 订阅事 ...

  6. 使用PHP来简单的创建一个RPC服务

    RPC全称为Remote Procedure Call,翻译过来为"远程过程调用".主要应用于不同的系统之间的远程通信和相互调用. 比如有两个系统,一个是PHP写的,一个是JAVA ...

  7. python 之 基础

    变量 变量的作用: 标识符的命名规范: 掌握常量与变n量的区别: 变量定义规范: 声明变量: name='Alex Li' 三部分:变量名 赋值运算符 变量值 变量定义规则:1.变量名只能是字母.数字 ...

  8. python学习笔记Day3

    set有点:1.访问速度快 2.天生解决了重复问题 tuple与set区别: 元组可重复,set不可重复创捷集合1 >>> s1.add('alex')>>> pr ...

  9. Linux驱动之LED驱动编写

    从上到下,一个软件系统可以分为:应用程序.操作系统(内核).驱动程序.结构图如下:我们需要做的就是写出open.read.write等驱动层的函数.一个LED驱动的步骤如下: 1.查看原理图,确定需要 ...

  10. hdu 5491(2015合肥网赛)The Next

    题目;http://acm.hdu.edu.cn/showproblem.php?pid=5491 题意就是,T组测试数据.然后L,S1,S2.L的二进制中有x个1,x满足  S1<=x< ...