当前位置:网站首页>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
}
}
边栏推荐
- [Video] ffplay uses MJPEG format to play USB camera
- FM信号、调制信号和载波
- To understand the difference between Gram-positive and Gram-negative bacteria and the difference in pathogenicity
- Drawing of clock dial
- 飞机引气系统的建模与故障仿真
- 基于STM32MP157调试MIPI-DSI屏幕
- C disk drives, folders and file operations
- MySQL简单权限管理
- Machine learning notes linear regression of time series
- socket问题记录
猜你喜欢
Electronics: Lesson 014 - Experiment 15: intrusion alarm (Part I)
洛谷P1073 [NOIP2009 提高组] 最优贸易(分层图+最短路)
基于STM32MP157调试MIPI-DSI屏幕
Opencv daily function structure analysis and shape descriptor (8) Fitline function fitting line
Electronics: Lesson 010 - Experiment 9: time and capacitors
深度学习系列48:DeepFaker
消息中间件之ActiveMQ的基本使用
Modular programming of LCD1602 LCD controlled by single chip microcomputer
Force buckle 272 Closest binary search tree value II recursion
使用报文和波形记录分析仪RoyalScope的帧统计功能排查CAN总线偶发性故障
随机推荐
C disk drives, folders and file operations
传统的IO存在什么问题?为什么引入零拷贝的?
使用Adobe Acrobat Pro调整PDF页面为统一大小
現在通過開戶經理發的開戶鏈接股票開戶安全嗎?
Electronics: Lesson 010 - Experiment 8: relay oscillator
Use the frame statistics function of the message and waveform recording analyzer royalscope to troubleshoot the accidental faults of the CAN bus
Requirements for Power PCB circuit board design 2021-11-09
C examples of using colordialog to change text color and fontdialog to change text font
Importer des données dans MATLAB
PCB board design - automatic layout 2021-10-15
【红旗杯?】补题
Electronics: Lesson 010 - Experiment 9: time and capacitors
云计算考试版本1.0
將數據導入到MATLAB
Startup, shutdown and restart of Oracle and MySQL on Linux
Electronics: Lesson 012 - Experiment 13: barbecue LED
挖掘微生物暗物质——新思路
ffmpeg+SDL2实现音频播放
Six causes of PCB disconnection 2021-10-20
DNS协议及其DNS完整的查询过程