51NOD 1244 莫比烏斯函式之和(杜教篩)

2021-08-14 07:00:32 字數 837 閱讀 3701

題目鏈結

分析:

首先,我們提出乙個關於mu函式的簡單性質:

即:

這樣,我們就可以像1239一樣

預處理出一部分的s函式,之後的s值用hash+記搜解決

mu[1]=1不要忘了

#include

#include

#include

#define ll long long

using namespace std;

const int n=5000002;

const int maxn=1e6+5;

int mu[n],sshu[500010],tot=0,f[maxn];

bool no[n];

ll n,m,h[maxn];

void make()

for (int j=1;j<=tot&&sshu[j]*i

no[sshu[j]*i]=1;

if (i%sshu[j]==0)

mu[i*sshu[j]]=-mu[i];}}

for (int i=2;i1];

}int hash(ll x)

ll cal(ll n)

h[l]=n; f[l]=x;

returnx;}

int main()

51nod1244 莫比烏斯函式之和

求 i lr i l,r 10 10設m n i 1 n i 我們知道,d n d n 1 那麼1 i 1 n d i d t 1n d t d i 1n d 1 ni d i 1 nm ni 於是,m n 1 i 2nm ni 後面的東西可以用分塊來加速。然後打上記憶化標記。或者可以先預處理出一段...

51NOD 1244 莫比烏斯函式之和

基準時間限制 3 秒 空間限制 131072 kb 分值 320 難度 7級演算法題 莫比烏斯函式,由德國數學家和天文學家莫比烏斯提出。梅滕斯 mertens 首先使用 n miu n 作為莫比烏斯函式的記號。具體定義如下 如果乙個數包含平方因子,那麼miu n 0。例如 miu 4 miu 12 ...

51nod 1244 莫比烏斯函式之和

莫比烏斯函式,由德國數學家和天文學家莫比烏斯提出。梅滕斯 mertens 首先使用 n miu n 作為莫比烏斯函式的記號。具體定義如下 如果乙個數包含平方因子,那麼miu n 0。例如 miu 4 miu 12 miu 18 0。如果乙個數不包含平方因子,並且有k個不同的質因子,那麼miu n 1...