BZOJ 4916 神犇和蒟蒻

2021-08-01 22:48:10 字數 697 閱讀 1202

很久很久以前,有乙隻神犇叫yzy;

很久很久之後,有乙隻蒟蒻叫lty;

請你讀入乙個整數n;1<=n<=1e9,a、b模1e9+7;

請你輸出乙個整數a=\sum_^n;

請你輸出乙個整數b=\sum_^n;

1by monster_yi

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

杜教篩~

推導詳見:

其中ni2和ni6分別是2和6的逆元,是用快速冪求出來的~

#include#includeusing namespace std;

#define ll long long

#define modd 1000000007

#define m 10000000

#define ni2 500000004

#define ni6 166666668

int n,q[m/5];

ll phi[m];

bool b[m];

mapf;

ll read()

while(ch>='0' && ch<='9')

return x*f;

}void init()

return f[n]=(now-re+modd)%modd;

}int main()

bzoj4916 神犇和蒟蒻

求 i 1n i2 和 i 1n i2 n 1e9,答案對1e9 7取模 被題目名字和ac人數騙進來,一看題還嚇了一跳 難道這是什麼最新的操作.jpg 然後仔細看了一眼題 mdzz這不是隨便做嗎?的話除了i 1不是全部為0嗎?的話把式子拆出來就可以發現 i2 i i 然後就直接上杜教篩就好了。隱藏水...

bzoj4916 神犇和蒟蒻

首先看第乙個式子,根據莫比烏斯函式的性質可知,當i 1時,i 1 其它都是0.所以輸出1 然後看第二個式子。根據尤拉函式的性質,平方的部分多出來的質因數已經出現過,所以式子變成 n i 1i i 這個用杜教篩來求。include include include include using names...

bzoj 4916 神犇和蒟蒻

description 很久很久以前,有乙隻神犇叫yzy 很久很久之後,有乙隻蒟蒻叫lty input 請你讀入乙個整數n 1 n 1e9,a b模1e9 7 output 請你輸出乙個整數a sum n 請你輸出乙個整數b sum n sample input 1 sample output 1 ...