on考慮將lcm
lcmlc
m分解質因數lcm
=∏pi
cilcm=\prod p_i^
lcm=∏p
ici
容易發現答案即為∑ci
\sum c_i
∑ci
顯然想到對n
nn進行根號分塊
不大於n
\sqrt n
n的質因數對答案做log
loglo
g次貢獻
大於n
\sqrt n
n的質因數只對答案做一次貢獻
前者線性篩後暴力計算,後者min
_25min\_25
min_25篩co
decode
code
#pragma gcc optimize(2)
%:pragma gcc optimize(3
)%:pragma gcc optimize
("ofast")%
:pragma gcc optimize
("inline"
)#include
#include
#include
#include
#include
#define ll long long
#define ll long long
#define rint register int
using
namespace std;ll n,res,sum,sq;
const
int maxn =
320000
;ll b[maxn]
;int s, a[maxn]
, s[maxn]
,vis[maxn]
,tot,prime[maxn]
;double inv[maxn]
;inline ll prime
(ll n)
else
i = s[i]
= s[s[i]];
ll q =
(ll)p * p, now = n / p;
int r = q <= s ? s : now / p;
for(rint i =
(s / p +1)
|1; i <= r;)if
(s[i]
== i)
else
i = s[i]
= s[s[i]];
if(q <= r)
for(rint i = q; i <= r; i +
= p)
if(s[i]
== i)
s[i]+=
2;for(rint i = s; i >= q;
--i) a[i]
-= a[
(int
)(i * inv[p]
+1e-9)]
- a[p -1]
;}return b[1]
;}inline ll read()
signed
main()
}for
(register
int k=
1;k<=tot;k++
)printf
("%lld"
,prime
(n)-
1-sum+res)
;}
牛客挑戰賽58
前i 1的二進位制相等,a的前n個數的前i 1位可以亂取,b的前n 1個數前i 1位也可以亂取,因為b的第n個數的前i 1異或可為任意值,所以sum1 2 i 1 n 2 i 1 n 1 2 i 1 2n 1 a的第i位為1且b的第i位為0 只要a的n數第i位中有乙個不為0的,a的第i位不為0,b的...
牛客挑戰賽44D 數列的和
因為換了題所以1h怒寫exp然後跑不動 生成函式亂推即可 ans sum m i x i sum j j 2k x j n 有 sum i x i frac sum i ix i frac sum i i 2x i frac frac 代入到後面的提出 frac 二項式展開後交換ij,把生成函式換成...
牛客Wannafly挑戰賽12 題解
傳送門 說是比賽題解,其實我只會前三題 後面的一定補 t1題意,在乙個長度為n的時間內,問如何選擇存款期限,使得收益最大。dp include include include include using namespace std define fi first define se second d...