欧拉函数
欧拉函数(Euler's totient function),即
例如
性质#
用法#
举个栗子:The Euler function
题意:求
如果枚举必定
方法一:
用埃氏筛,由欧拉函数的展开式
对于筛出的每个质数
时间复杂度
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
template<typename P>
inline void read(P &x){
P res=0,f=1;
char ch=getchar();
while(ch<'0' || ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9'){
res=res*10+ch-'0';
ch=getchar();
}
x=res*f;
}
using namespace std;
const int N=3000005;
int a[N],b[N],tot=1,maxn;
int phi[N];
void initprime(int n){
for(int i=2;i<=n;i++) phi[i]=(int)i;
for(int i=2;i<=n;i++) if(phi[i]==(int)i)
for(int j=i;j<=n;j+=i) phi[j]/=(int)i,phi[j]*=(int)(i-1);
for(int i=1;i<=n;i++) phi[i]+=phi[i-1];
}
signed main(){
auto solve=[&](){
while(scanf("%d%d",&a[tot],&b[tot])!=EOF) maxn=max(maxn,b[tot]),tot++;
initprime(maxn);
for(int i=1;i<tot;i++) printf("%lld\n",phi[b[i]]-phi[a[i]-1]);
return;
};
return 0;
}
方法二自己搜,不想写了。
作者:God_Max_Me
出处:https://www.cnblogs.com/lizihan00787/p/18323136
版权:本作品采用「God_Max_Me-非商业性使用」许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端