当前位置:网站首页>数论模板啊
数论模板啊
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];//前缀和
}
}
边栏推荐
- 417-二叉树的层序遍历1(102. 二叉树的层序遍历、107.二叉树的层次遍历 II、199.二叉树的右视图、637.二叉树的层平均值)
- Atlassian Confluence 远程代码执行漏洞(CVE-2022-26134漏洞分析与防护
- 单位转换-毫米转像素-像素转毫米
- 产品经理专业知识50篇(四)-从问题到能力提升:AMDGF模型工具
- Atlas conflict Remote Code Execution Vulnerability (cve-2022-26134 vulnerability analysis and protection
- [daily training] 207 Class Schedule Card
- Use the frame statistics function of the message and waveform recording analyzer royalscope to troubleshoot the accidental faults of the CAN bus
- Runtime - Methods member variable, cache member variable
- 基于Anaconda的模块安装与注意事项
- Modular programming of LCD1602 LCD controlled by single chip microcomputer
猜你喜欢
随机推荐
Force deduction 76 questions, minimum covering string
VOCALOID笔记
取消word文档中某些页面的页眉
navicat定时任务无效
【补题】2021牛客暑期多校训练营9-n
力扣78:子集
机器学习笔记 - 时间序列的线性回归
PCB board design - automatic layout 2021-10-15
Tips on how to design soft and hard composite boards ~ 22021/11/22
27. 移除元素
黑点==白点(MST)
What are the problems with traditional IO? Why is zero copy introduced?
2160. minimum sum of the last four digits after splitting
挖掘微生物暗物质——新思路
How to resize an image in C #
MySQL simple permission management
剑指offer刷题(简单等级)
Linux上oracle和mysql的启动,关闭,重启
What are the benefits of reserving process edges for PCB production? 2021-10-25
ts环境搭建









