当前位置:网站首页>数论模板啊
数论模板啊
2022-06-25 06:43:00 【mfy的1号小迷弟】
求单个phi(很大)
inline ll getphi(ll x){
ll res=x;
for(ll i=2;i*i<=x;i++){
if(x%i==0){
res=res/i*(i-1);
while(x%i==0) x/=i;
}
}
if(x>1) res=res/x*(x-1);
return res;
}
求一群phi很小
void get_phi()
{
int i, j, k;
k = 0;
for(i = 2; i < maxn; i++)
{
if(is_prime[i] == false)
{
prime[k++] = i;
phi[i] = i-1;
}
for(j = 0; j<k && i*prime[j]<maxn; j++)
{
is_prime[ i*prime[j] ] = true;
if(i%prime[j] == 0)
{
phi[ i*prime[j] ] = phi[i] * prime[j];
break;
}
else
{
phi[ i*prime[j] ] = phi[i] * (prime[j]-1);
}
}
}
}
欧拉筛得到素数表
void get_prime() //欧拉筛得到素数表
{
memset(vis,0,sizeof(vis));
tot=0;
for(int i=2;i<=maxn;i++)
{
if(!vis[i])
prime[++tot]=i;
for(int j=1;j<=tot&&i*prime[j]<=maxn;j++)
{
vis[i*prime[j]]=true;
if(i%prime[j]==0)
break;
}
}
}
线性筛求莫比乌斯函数
void init(){
//线性筛莫比乌斯函数
f[1]=mu[1]=1;
for(int i=2;i<=N;i++){
if(vis[i]==0){
prime[++cnt]=i;
mu[i]=-1;//单个的mu值
}
for(int j=1;j<=cnt;j++){
if(i*prime[j]>N)break;
vis[i*prime[j]]=1;
mu[i*prime[j]]=i%prime[j]?-mu[i]:0;
if(i%prime[j]==0)break;
}
f[i]=f[i-1]+mu[i];//前缀和
}
}
边栏推荐
猜你喜欢

The fourth floor is originally the fourth floor. Let's have a look

差点被这波Handler 面试连环炮带走~

Apache CouchDB 代码执行漏洞(CVE-2022-24706 )批量POC

Hisilicon 3559 sample parsing: Vio

Three Siemens fire-fighting hosts fc18 are equipped with can optical transceiver for optical fiber redundant ring network networking test

剑指offer刷题(简单等级)

NPM install reports an error: gyp err! configure error

PCB board design - automatic layout 2021-10-15

【QT】Qt 5 的程序:打印文档

C#中如何调整图像大小
随机推荐
27. remove elements
[daily training] 207 Class Schedule Card
如何用svn新建属于自己的分支
将数据导入到MATLAB
【补题】2021牛客暑期多校训练营9-n
个人域名和企业域名的区别
2160. minimum sum of the last four digits after splitting
判断用户是否是第一次进入某个页面
Microsoft Office Word 远程命令执行漏洞(CVE-2022-30190)分析与利用
[single chip microcomputer project training] multipoint temperature wireless acquisition system based on nRF905
Cifar-10 dataset application: quick start data enhancement method mixup significantly improves image recognition accuracy
將數據導入到MATLAB
VSCode很好,但我以后不会再用了
基于STM32MP157调试MIPI-DSI屏幕
洛谷P2048 [NOI2010] 超级钢琴(RMQ+优先队列)
2160. 拆分数位后四位数字的最小和
Knowledge sharing 𞓜 conventional laminated structure of six layer PCB
CAN总线工作状况和信号质量“体检”
Use the frame statistics function of the message and waveform recording analyzer royalscope to troubleshoot the accidental faults of the CAN bus
Linux上oracle和mysql的启动,关闭,重启