[LOJ6053] 简单的函数 [Min25筛]

Posted qq62c30ac77b2a7

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LOJ6053] 简单的函数 [Min25筛]相关的知识,希望对你有一定的参考价值。

​传送门​

[LOJ6053], 然后就是Min25的板子题,要特殊考虑 2 的影响

#include<bits/stdc++.h>
#define N 400050
using namespace std;
typedef long long ll;
const int Mod = 1e9 + 7, inv2 = (Mod+1)/2;
ll add(ll a, ll b) return (a + b) % Mod;
ll mul(ll a, ll b) return a * b % Mod;
ll n, m, S, prim[N]; int tot; bool isp[N];
ll w[N], id1[N], id2[N], f0[N], f1[N], s[N];
void prework()
for(int i = 2; i <= N-50; i++)
if(!isp[i]) prim[++tot] = i, s[tot] = s[tot-1] + i;
for(int j = 1; j <= tot; j++)
if(i * prim[j] > N-50) break;
isp[i * prim[j]] = 1; if(i % prim[j] == 0) break;



ll Id(ll x) return x <= S ? id1[x] : id2[n/x];
ll Solve(ll x, int p)
if(x <= 1 || prim[p] > x) return 0;
ll k = Id(x), ans = add(add(f1[k], Mod-f0[k]), Mod - add(s[p-1], Mod-(p-1)));
if(p == 1) ans += 2;
for(int i = p; i <= tot && prim[i] * prim[i] <= x; i++)
for(ll e = 1, l = prim[i]; l <= x; e++, l *= prim[i])
ans = add(ans, mul((prim[i] ^ e), Solve(x/l, i+1) + (e>1)));

return ans;

int main()
scanf("%lld", &n); S = sqrt(n); prework();
for(ll l = 1, r; l <= n; l = r+1)
ll v = n/l; r = n/v; if(v <= S) id1[v] = ++m; else id2[n/v] = ++m;
w[m] = v;
ll x = w[m] % Mod;
f0[m] = x-1;
f1[m] = mul(inv2, mul(x, x+1))-1;

for(int i = 1; i <= tot; i++)
for(int j = 1; j <= m, prim[i] * prim[i] <= w[j]; j++)
ll k = Id(w[j] / prim[i]);
f0[j] = add(f0[j], Mod - f0[k] + (i-1));
f1[j] = add(f1[j], Mod - mul(prim[i], f1[k] - s[i-1]));


cout << add(Solve(n, 1), 1); return 0;

 


以上是关于[LOJ6053] 简单的函数 [Min25筛]的主要内容,如果未能解决你的问题,请参考以下文章

区间素数个数(Min_25筛)

[LOJ572] Misaka Network 与求和 [杜教筛+Min25]

LG5325 模板Min_25筛

LibreOJ - 6053(积性函数前缀和,pn筛角度)

LibreOJ - 6053(积性函数前缀和,pn筛角度)

Min25筛