当前位置:网站首页>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
}
}
边栏推荐
- Anaconda navigator启动慢的一个解决方法
- 【Unexpected token o in JSON at position 1出错原因及解决方法】
- 取消word文档中某些页面的页眉
- [little knowledge] PCB proofing process
- 27. remove elements
- 50 pieces of professional knowledge of Product Manager (IV) - from problem to ability improvement: amdgf model tool
- 数论模板啊
- Matlab代码格式一键美化神器
- How to create a new branch with SVN
- 【莫比乌斯反演】
猜你喜欢

Force buckle 272 Closest binary search tree value II recursion

电子学:第011课——实验 10:晶体管开关

Mining microbial dark matter -- a new idea

Opencv minimum filtering (not limited to images)

Can transparent cloud gateway caniot and candtu record can messages and send and receive can data remotely

Introduction to the main functions of the can & canfd comprehensive test and analysis software lkmaster of the new usbcan card can analyzer

Application of can optical transceiver of ring network redundant can/ optical fiber converter in fire alarm system

Ubuntu18下登录mysql 5.7设置root密码

使用Adobe Acrobat Pro调整PDF页面为统一大小

电子学:第013课——实验 14:可穿戴的脉冲发光体
随机推荐
Tips 𞓜 how to clean PCB boards 2021-10-22
电子学:第013课——实验 14:可穿戴的脉冲发光体
不怕百战失利,就怕灰心丧气
Advantages and differences of three kinds of vias in PCB 2021-10-27
【补题】2021牛客暑期多校训练营1-3
【补题】2021牛客暑期多校训练营4-n
How to select lead-free and lead-free tin spraying for PCB? 2021-11-16
50. pow (x, n) - fast power
Apache CouchDB 代码执行漏洞(CVE-2022-24706 )批量POC
Use the frame statistics function of the message and waveform recording analyzer royalscope to troubleshoot the accidental faults of the CAN bus
Tips on how to design soft and hard composite boards ~ 22021/11/22
静态网页服务器
【Unexpected token o in JSON at position 1出错原因及解决方法】
一文了解 | 革兰氏阳性和阴性菌区别,致病差异,针对用药
C#控件刷新
产品经理专业知识50篇(四)-从问题到能力提升:AMDGF模型工具
【日常训练】207. 课程表
黑点==白点(MST)
What are the problems with traditional IO? Why is zero copy introduced?
洛谷P2048 [NOI2010] 超级钢琴(RMQ+优先队列)