[BZOJ4802]欧拉函数
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]欧拉函数的更多相关文章
- bzoj4802 欧拉函数(附Millar-Rabin和Pollard-Rho讲解)
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4802 [题解] 参考:http://www.matrix67.com/blog/archiv ...
- BZOJ4802:欧拉函数(Pollard-Rho,欧拉函数)
Description 已知N,求phi(N) Input 正整数N.N<=10^18 Output 输出phi(N) Sample Input 8 Sample Output 4 Soluti ...
- BZOJ4802 欧拉函数 (Pollard-Rho Miller-Robin)
题目 求大数的欧拉函数φ\varphiφ 题解 Pollard-Rho 板子 CODE #pragma GCC optimize (3) #include <bits/stdc++.h> ...
- [日常摸鱼]bzoj4802 欧拉函数-PollardRho大整数分解算法
啊居然要特判,卡了好久QAQ (好像Windows下的rand和Linux下的不一样? QwQ一些东西参考了喵铃的这篇blog:http://www.cnblogs.com/meowww/p/6400 ...
- BZOJ4802 欧拉函数 数论
原文链接http://www.cnblogs.com/zhouzhendong/p/8117744.html 题目传送门 - BZOJ4802 题意概括 Description 已知N,求phi(N) ...
- 2018.12.17 bzoj4802: 欧拉函数(Pollard-rho)
传送门 Pollard−rhoPollard-rhoPollard−rho模板题. 题意简述:求ϕ(n),n≤1e18\phi(n),n\le 1e18ϕ(n),n≤1e18 先把nnn用Pollar ...
- 【BZOJ4802】欧拉函数(Pollard_rho)
[BZOJ4802]欧拉函数(Pollard_rho) 题面 BZOJ 题解 这么大的范围肯定不好杜教筛. 考虑欧拉函数的计算式,显然只需要把\(n\)分解就好了. 直接\(Pollard\_rho\ ...
- BZOJ 4802 欧拉函数
4802: 欧拉函数 Description 已知N,求phi(N) Input 正整数N.N<=10^18 Output 输出phi(N) Sample Input 8 Sample Outp ...
- bzo4802 欧拉函数 miller_rabin pollard_rho
欧拉函数 Time Limit: 5 Sec Memory Limit: 256 MBSubmit: 1112 Solved: 418[Submit][Status][Discuss] Descr ...
随机推荐
- (转)关于EntityFramework中连接字符串的说明
1. 基本格式 <connectionStrings> <add name="MyEntities" connectionString="metadat ...
- InstallShield 2015 Premier的Basic MSI Project如何在卸载时删除残留的文件 (转)
转载:http://blog.csdn.net/zztoll/article/details/54018615#comments 先说下缘由,我在用InstallShield 2015 Premier ...
- python常见容器属性和方法
`````字符串中反斜杠字符表 转义格式 意义 \' 单引号(') \" 双引号(") \\ 反斜杠(\ ) \n 换行 \r 返回光标至行首 \f 换页 \t ...
- codeforces 9 div2 C.Hexadecimal's Numbers 暴力打表
C. Hexadecimal's Numbers time limit per test 1 second memory limit per test 64 megabytes input stand ...
- python 判断是否是元音字母
def is_vowel(char): all_vowels = 'aeiou' return char in all_vowels print(is_vowel('c')) print(is_vow ...
- Flutter基础Widget之按钮(RaisedButton、FlatButton、OutlineButton,IconButton)
Flutter中给我们预先定义好了一些按钮控件给我们用,常用的按钮如下 RaisedButton :凸起的按钮,其实就是Android中的Material Design风格的Button ,继承自Ma ...
- UriComponentsBuilder和UriComponents url编码
Spring MVC 提供了一种机制,可以构造和编码URI -- 使用UriComponentsBuilder和UriComponents. 功能相当于 urlencode()函数,对url进行编码, ...
- 关于keyCode, 键盘代码。 和零散的javascript知识。http://js2.coffee/(转化工具)
这个是coffeescript代码 document.addEventListener 'turbolinks:load', -> document.getElementById(" ...
- UVALive-3645 Objective: Berlin (最大流:时序模型)
题目大意:有n个城市,m条航班.已知每条航班的起点和终点,还有每条航班的载客量.出发时间.到达时间.并且要求在任何一个城市(起点.终点除外)都至少要有30分钟的中转时间,求起点到终点的最大客流量. 题 ...
- ExecutorService对象的shutdown()和shutdownNow()的区别
可以关闭 ExecutorService,这将导致其拒绝新任务.提供两个方法来关闭 ExecutorService. shutdown() 方法在终止前允许执行以前提交的任务; shutdownNow ...