当前位置:网站首页>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
}
}
边栏推荐
- Looking for b-end product manager after years? I almost ruined myself
- Six causes of PCB disconnection 2021-10-20
- Atlas conflict Remote Code Execution Vulnerability (cve-2022-26134 vulnerability analysis and protection
- C examples of using colordialog to change text color and fontdialog to change text font
- 飞机引气系统的建模与故障仿真
- bat启动.NET Core
- allgero报错:Program has encountered a problem and must exit. The design will be saved as a .SAV file
- 消息中间件之ActiveMQ的基本使用
- 牛客:飞行路线(分层图+最短路)
- ffmpeg+SDL2实现音频播放
猜你喜欢

电子学:第012课——实验 13:烧烤 LED

Tips on how to design soft and hard composite boards ~ 22021/11/22

Ph中和过程建模

c#ColorDialog更改文本颜色和FontDialog更改文本字体的使用示例

Matlab代码格式一键美化神器

环网冗余式CAN/光纤转换器的CAN光端机在消防火灾联网报警系统中的应用

FM信号、调制信号和载波

深度学习系列48:DeepFaker

TCP的那点玩意儿

Application of can optical transceiver of ring network redundant can/ optical fiber converter in fire alarm system
随机推荐
420-二叉树的层序遍历2(429. N 叉树的层序遍历、515.在每个树行中找最大值、116.填充每个节点的下一个右侧节点指针、104.二叉树的最大深度、111.二叉树的最小深度)
27. remove elements
Atlas conference vulnerability analysis collection
C examples of using colordialog to change text color and fontdialog to change text font
Drawing of clock dial
Est - il sûr d'ouvrir un compte d'actions maintenant via le lien d'ouverture de compte coiffé?
Vscode is good, but I won't use it again
电子学:第011课——实验 10:晶体管开关
深度学习系列48:DeepFaker
【补题】2021牛客暑期多校训练营4-n
【补题】2021牛客暑期多校训练营1-3
Is it safe to open an account through the haircut account opening link now?
基于STM32MP157调试MIPI-DSI屏幕
Dietary intervention reduces cancer treatment-related symptoms and toxicity
将数据导入到MATLAB
Pycharm的奇葩设定:取消注释后立马复制会带上#
Looking for b-end product manager after years? I almost ruined myself
Technology blog | how to communicate using SSE
navicat定时任务无效
SCM Project Training