bzoj

description

给出\(n\),求\(\varphi(n)\)。\(n\le10^{18}\)

sol

\(Pollard\ Rho\),存个代码。

code

#include<cstdio>
#include<algorithm>
#include<ctime>
using namespace std;
#define ll long long
ll p[100],len;
ll mul(ll x,ll y,ll mod){
x%=mod;y%=mod;ll res=0;
while(y){if(y&1)res=(res+x)%mod;x=(x+x)%mod;y>>=1;}
return res;
}
ll fastpow(ll x,ll y,ll mod){
x%=mod;ll res=1;
while(y){if(y&1)res=mul(res,x,mod);x=mul(x,x,mod);y>>=1;}
return res;
}
bool MR(ll n){
if (n==2) return true;
for (int i=1;i<=10;++i){
ll x=1ll*rand()*rand()%(n-2)+2,p=n-1;
if (fastpow(x,p,n)!=1) return false;
while (~p&1){
p>>=1;ll y=fastpow(x,p,n);
if (mul(y,y,n)==1&&y!=1&&y!=n-1) return false;
}
}
return true;
}
ll PR(ll n,ll c){
ll i=0,k=2,x,y;x=y=1ll*rand()*rand()%(n-1)+1;
while (1){
x=(mul(x,x,n)+c)%n;
ll d=__gcd((y-x+n)%n,n);
if (d!=1&&d!=n) return d;
if (x==y) return n;
if (++i==k) y=x,k<<=1;
}
}
void fact(ll n,ll c){
if (n==1) return;
if (MR(n)) {p[++len]=n;return;}
ll p=n,k=c;
while (p>=n) p=PR(p,c--);
fact(p,k);fact(n/p,k);
}
int main(){
ll n;scanf("%lld",&n);fact(n,666);
sort(p+1,p+len+1);len=unique(p+1,p+len+1)-p-1;
ll res=n;
for (int i=1;i<=len;++i) res=res/p[i]*(p[i]-1);
printf("%lld\n",res);
return 0;
}

[BZOJ4802]欧拉函数的更多相关文章

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

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

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

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

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

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

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

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

  5. BZOJ4802 欧拉函数 数论

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

  6. 2018.12.17 bzoj4802: 欧拉函数(Pollard-rho)

    传送门 Pollard−rhoPollard-rhoPollard−rho模板题. 题意简述:求ϕ(n),n≤1e18\phi(n),n\le 1e18ϕ(n),n≤1e18 先把nnn用Pollar ...

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

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

  8. BZOJ 4802 欧拉函数

    4802: 欧拉函数 Description 已知N,求phi(N) Input 正整数N.N<=10^18 Output 输出phi(N) Sample Input 8 Sample Outp ...

  9. bzo4802 欧拉函数 miller_rabin pollard_rho

    欧拉函数 Time Limit: 5 Sec  Memory Limit: 256 MBSubmit: 1112  Solved: 418[Submit][Status][Discuss] Descr ...

随机推荐

  1. wcf 远程服务器返回了意外响应: (413) Request Entity Too Large。

    我遇到这个问题的原因是:我使用asp.net 网站调用wcf服务后,通过方法提交数据产生的.我提交的数据是一个实体,包含很多字符串和图片格式的二进制数据超过4M 就报个错误. 后来同事帮忙解决了.他说 ...

  2. rails性能优化

    1,使用Unicorn或者Thin服务器替代默认的webrick.2,静态资源压缩合并,放到云存储上.3,同时可以使用rails的Turbolinks,使用js替换title和body,但也带来了js ...

  3. rails常用gem

    一,开发模式下 1,better_errors 使用全新的页面替换 Rails 默认的错误页面,显示更多的上下文信息,例如源码 和变量的值:配合binding_of_caller可以执行代码查看变量的 ...

  4. Atcoder CADDi 2018 Solution

    C - Product and GCD Solved. 题意: 给出$n个数$的乘积,求$这n个数$的最大的可能是GCD 思路: 分解质因子,那么$每个质因子的贡献就是其质因子个数/ n的乘积$ #i ...

  5. 20155316 2016-2017-2 《Java程序设计》第8周学习总结

    教材学习内容总结 课堂部分要点 数据结构与算法 与 Java相结合 collection API:数据结构 crypt:密码学 操作系统 考试部分重点 实验楼:Linux第四节 教材:第6章.第14章 ...

  6. foo、bar美国版的张三李四

    不管看javascript还是其他语言举例,经常看到使用foo和bar来充当变量.那么究竟foo.bar是什么鬼? 一说:foo 和 bar 组合在一起所构成的 foobar 应该最能反映其原始的意思 ...

  7. 20145312《网络对抗》Exp4 恶意代码分析

    20145312<网络对抗>Exp4 恶意代码分析 问题回答 1.总结一下监控一个系统通常需要监控什么.用什么来监控. 监控一个系统通常需要监控这个系统的注册表,进程,开放端口,程序服务还 ...

  8. Installing VirtualBox DKMS in Kali 2.0

    Kali linux is one of the mainly used operating system by the Ethical hackers and information securit ...

  9. 为pyhon安装opencv扩展包出现distributed 1.21.8 requires msgpack, which is not installed.【转】

    本文转载自:https://blog.csdn.net/weixin_39513374/article/details/81051466 pip install msgpack-python pip ...

  10. 采用注解方式实现security

    采用注解方式使用security,首先我们需要用注解方式实现Spring MVC,新建一个Maven项目 本项目目录结构如下:  我们会发现在WEB-INF中没有web.xml文件,下面会介绍,采用j ...