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

Description

已知N,求phi(N)

Input

正整数N。N<=10^18

Output

输出phi(N)

Sample Input

8

Sample Output

4

Solution

一开始读错题了……以为是求约束个数和……

读对题之后然后发现我不会就问旁边的宽嫂……

宽嫂:这不是欧拉函数的定义式么?我初中就会了啊。

我:aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAA1AEYDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD6przvxJ8QfDWgXn2PUtYiivfK/wBRFFLPKv8A36ra8XT3Gn+H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28t4vPs5dKvPP/wCWUEv/AC1i/wCmtdhYwWeheH4oIv3Vlp0Hlf8AbKKKgDn/AIIXn2z4ZeF/N/1sVn5X/fr91XoleXfAu18j4W+GfN/1skXm/wDf2Xza9RoAKKKKACua0/Q7DSfNhsYFjSeW4uHx/ebrRRQB0NSUUUAFVTAs1vtl+YUUUAQwQxwiKGJdsXlfdrQoooAKKKKAP//Z" alt="" />

然后去百度了一发,发现一个数的欧拉函数就是

$\prod (p_i-1)*p_i^{k_i-1}$,其中$p_i$是这个数的质因子,$k_i$是这个质因子的次数……

然后套板子就行了。

发现我之前抄了个假的快速乘然后还花了我一会儿改代码+改博客……QAQ

Code

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#define LL long long
using namespace std; LL n,ans=,Num[],cnt;
LL prime[]={,,,,,,,,,,};
map<LL,LL>Keg; LL Mul(LL a,LL b,LL MOD)
{
LL tmp=a*b-(LL)((long double)a*b/MOD+0.1)*MOD;
return tmp<?tmp+MOD:tmp;
} LL Qpow(LL a,LL b,LL MOD)
{
LL ans=;
while (b)
{
if (b&) ans=Mul(ans,a,MOD);
a=Mul(a,a,MOD); b>>=;
}
return ans;
} LL gcd(LL a,LL b) {return b==?a:gcd(b,a%b);} bool Miller_Rabin(LL n)
{
if (n==) return ;
if (n< || n%==) return ;
LL m=n-,l=;
while (m%==) m>>=, l++;
for (int i=; i<; ++i)
{
LL p=prime[i],w=Qpow(p,m,n);
if (w==n- || w== || p==n) continue;
for (int j=; j<=l; ++j)
{
LL u=Mul(w,w,n);
if (u== && w!=n- && w!=) return ;
w=u;
}
if (w!=) return ;
}
return ;
} LL Pollard_Rho(LL n,LL c)
{
LL x=(rand()+)%n,y=x,p=,k=;
for (LL i=; p==; ++i)
{
x=(Mul(x,x,n)+c)%n;
p=x>y?x-y:y-x;
p=gcd(p,n);
if (i==k) y=x, k=k+k;
}
return p;
} void Solve(LL n)
{
if (n==) return;
if (Miller_Rabin(n))
{
if (!Keg[n]) Num[++cnt]=n;
++Keg[n]; return;
}
LL t=n;
while (t==n) t=Pollard_Rho(n,rand()%(n-)+);
Solve(t); Solve(n/t);
} int main()
{
scanf("%lld",&n);
Solve(n);
for (int i=; i<=cnt; ++i)
ans=ans*(Num[i]-)*Qpow(Num[i],Keg[Num[i]]-,2e18);
printf("%lld\n",ans);
}
上一篇:SpringBoot之SpringSecurity权限注解在方法上进行权限认证多种方式


下一篇:用户角色权限查询添加bug集锦 用户密码加密 MD5 加盐 随机盐 spring的加密bcrypt