当前位置:网站首页>Number theory template
Number theory template
2022-06-25 08:02:00 【Mfy's little brother 1】
Seek single phi( It's big )
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;
}
Ask for a group phi Very small
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);
}
}
}
}
Euler sieve gets prime number table
void get_prime() // Euler sieve gets prime number table
{
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;
}
}
}
Solving Mobius function by linear sieve
void init(){
// Linear sieve Mobius function
f[1]=mu[1]=1;
for(int i=2;i<=N;i++){
if(vis[i]==0){
prime[++cnt]=i;
mu[i]=-1;// A single mu value
}
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 prefix and
}
}
边栏推荐
猜你喜欢

Knowledge sharing 𞓜 conventional laminated structure of six layer PCB

电子学:第008课——实验 6:非常简单的开关

Anaconda navigator启动慢的一个解决方法

Ph中和过程建模

50 pieces of professional knowledge of Product Manager (IV) - from problem to ability improvement: amdgf model tool

Machine learning notes linear regression of time series

Opencv minimum filtering (not limited to images)

力扣 272. 最接近的二叉搜索树值 II 递归

TCP与UDP

CAN透传云网关CANIOT,CANDTU记录CAN报文远程收发CAN数据
随机推荐
2160. minimum sum of the last four digits after splitting
Functions should not specify operation types through variables
CAN透传云网关CANIOT,CANDTU记录CAN报文远程收发CAN数据
力扣 272. 最接近的二叉搜索树值 II 递归
基于Anaconda的模块安装与注意事项
2265. number of nodes with statistical value equal to the average value of subtree
[deep learning lightweight backbone] 2022 edgevits CVPR
Do you know why the PCB produces tin beads? 2021-09-30
Analysis of kinsing dual platform mining family virus
【论文学习】《VQMIVC》
Opencv daily function structure analysis and shape descriptor (8) Fitline function fitting line
c#磁盘驱动器及文件夹还有文件类的操作
【莫比乌斯反演】
Determine whether the user is entering a page for the first time
Startup, shutdown and restart of Oracle and MySQL on Linux
【补题】2021牛客暑期多校训练营6-n
MySQL interview - the response of executing SQL is relatively slow, and the troubleshooting ideas.
【视频】ffplay 使用mjpeg格式播放usb摄像头
Force deduction 76 questions, minimum covering string
洛谷P2048 [NOI2010] 超级钢琴(RMQ+优先队列)