当前位置:网站首页>Min25 sieve
Min25 sieve
2022-06-12 02:37:00 【doctorZ_】
Defining a product function f ( x ) f(x) f(x), f ( p c ) f(p^c) f(pc) It can be expressed as multiple completely integrable functions h i ( p c ) h_i(p^c) hi(pc) Add up , seek
∑ i = 1 n f ( i ) \sum_{i=1}^nf(i) i=1∑nf(i)
∑ i = 1 n f ( i ) = ∑ p ≤ n f ( p ) + ∑ i i s n o t a p r i m e f ( i ) \sum_{i=1}^nf(i)=\sum_{p\le n}f(p)+\sum_{i\ is\ not\ a\ prime}f(i) i=1∑nf(i)=p≤n∑f(p)+i is not a prime∑f(i)
set up g ( i , j , k ) g(i,j,k) g(i,j,k) Express ∑ w = 1 n [ w ∈ p r i m e ∣ m i n p > p j ] h k ( w ) \sum_{w=1}^n[w\in prime|minp>p_j]h_k(w) ∑w=1n[w∈prime∣minp>pj]hk(w)
g ( i , j , k ) = g ( i , j − 1 , k ) − [ g ( ⌊ i p j ⌋ , j − 1 , k ) − g ( p j − 1 , j − 1 , k ) ] h k ( p j ) g(i,j,k)=g(i,j-1,k)-[g(\lfloor\frac{i}{p_j}\rfloor,j-1,k)-g(p_j-1,j-1,k)]h_k(p_j) g(i,j,k)=g(i,j−1,k)−[g(⌊pji⌋,j−1,k)−g(pj−1,j−1,k)]hk(pj)
g ( i , m a x p r i m e , k ) g(i,maxprime,k) g(i,maxprime,k) said ∑ p ≤ i h k ( p ) \sum_{p\le i}h_k(p) ∑p≤ihk(p)
set up S ( n , x ) S(n,x) S(n,x) Express ∑ w = 1 n [ m i n p > p j ] f ( w ) \sum_{w=1}^n[minp>p_j]f(w) ∑w=1n[minp>pj]f(w)
S ( n , x ) = H ( n ) − H ( p x ) + ∑ p k e ≤ n , k > x [ S ( ⌊ n p e ⌋ , k ) + ( e ≠ 1 ) ] f ( p e ) S(n,x)=H(n)-H(p_x)+\sum_{p_k^e\le n,k>x}[S(\lfloor\frac{n}{p^e}\rfloor,k)+(e\not =1)]f(p^e) S(n,x)=H(n)−H(px)+pke≤n,k>x∑[S(⌊pen⌋,k)+(e=1)]f(pe)
∑ i = 1 n f ( i ) = S ( n , 0 ) \sum_{i=1}^nf(i)=S(n,0) ∑i=1nf(i)=S(n,0)
Fine implementation , It can be done O ( n 3 4 log n ) O(\frac{n^\frac{3}{4}}{\log n}) O(lognn43)
P5325 【 Templates 】Min_25 sieve
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;
const ll mod=1e9+7,inv2=500000004,inv3=333333336;
ll ksm(ll a,ll b)
{
ll res=1;
while(b)
{
if(b&1) res=res*a%mod;
a=a*a%mod,b>>=1;
}
return res;
}
const int N=2e6+1000;
ll n,w[N+10],sp1[N+10],sp2[N+10],g1[N+10],g2[N+10];int m,cnt,id1[N+10],id2[N+10],prime[N+10];
bool vis[N+10];
int id(ll x)
{
if(x<=m) return id1[x];
else return id2[n/x];
}
void init()
{
m=sqrt(n);
for(int i=2;i<=m;i++)
{
if(!vis[i]) prime[++prime[0]]=i,sp1[prime[0]]=(sp1[prime[0]-1]+i)%mod,sp2[prime[0]]=(sp2[prime[0]-1]+1ll*i*i%mod)%mod;
for(int j=1;j<=prime[0]&&i*prime[j]<=m;j++)
{
vis[i*prime[j]]=true;
if(i%prime[j]==0) break;
}
}
}
ll S(ll n,int x)
{
if(prime[x]>=n) return 0;
int l=id(n);
ll res=(g2[l]+mod-g1[l]+mod-(sp2[x]-sp1[x]))%mod;
for(int i=x+1;i<=prime[0]&&1ll*prime[i]*prime[i]<=n;i++)
{
ll pe=prime[i],tmp;
for(int e=1;pe<=n;e++,pe=pe*prime[i]) tmp=pe%mod,res=(res+tmp*(tmp-1)%mod*(S(n/pe,i)+(e!=1))%mod)%mod;
}
return res;
}
int main()
{
scanf("%lld",&n),init();
for(ll l=1,r;l<=n;l=r+1)
{
r=n/(n/l),w[++cnt]=n/l;
g1[cnt]=(w[cnt]%mod+2)*(w[cnt]%mod+mod-1)%mod*inv2%mod,g2[cnt]=(w[cnt]%mod*(w[cnt]%mod+1)%mod*(w[cnt]*2%mod+1)%mod*inv2%mod*inv3%mod+mod-1)%mod;
if(w[cnt]<=m) id1[w[cnt]]=cnt;
else id2[n/w[cnt]]=cnt;
}
for(int i=1;i<=prime[0];i++)
for(int j=1;j<=cnt&&1ll*prime[i]*prime[i]<=w[j];j++)
g1[j]=(g1[j]+mod-(g1[id(w[j]/prime[i])]+mod-sp1[i-1])%mod*prime[i]%mod)%mod,
g2[j]=(g2[j]+mod-(g2[id(w[j]/prime[i])]+mod-sp2[i-1])%mod*prime[i]%mod*prime[i]%mod)%mod;
printf("%lld",(S(n,0)+1)%mod);
return 0;
}
边栏推荐
- Maya Front Office Rendering plug - in Mel script Tool
- 力扣解法汇总942-增减字符串匹配
- Apache simple honeypot
- How to make div 100% page (not screen) height- How to make a div 100% of page (not screen) height?
- A single quarter of educational technology revenue of 230million: a year-on-year decrease of 51% and a sharp narrowing of net loss
- 力扣解法汇总933-最近的请求次数
- Force deduction solution summary 433- minimum gene change
- 力扣解法汇总668-乘法表中第k小的数
- 中国银屑病药物市场评估与投资方向研究报告(2022版)
- 跨域有哪些解决方法?
猜你喜欢

Getting started with RPC

Layered architecture of DDD

Maya foreground rendering plug-in Mel scripting tool

Intel case

WPS table learning notes - highlight duplicate values

Intel case

【高代码文件格式API】道宁为您提供文件格式API集——Aspose,只需几行代码即可创建转换和操作100多种文件格式

El upload upload file

Abaqus中批量对节点施加集中力荷载

一起教育科技单季营收2.3亿:同比降51% 净亏大幅收窄
随机推荐
Depth copy
Ue4\ue5 touch screen touch event: single finger and double finger
Force deduction solution summary 875- coco who likes bananas
Penetration test - file upload
Getting started with RPC
Acl2022 | DCSR: a sentence aware contrastive learning method for open domain paragraph retrieval
力扣解法汇总450-删除二叉搜索树中的节点
About 100 to realize the query table? Really? Let's experience the charm of amiya.
maya前臺渲染插件mel脚本工具
errno: -4091, syscall: ‘listen‘, address: ‘::‘, port: 8000
Apache simple honeypot
Maya foreground rendering plug-in Mel scripting tool
高考完不要急着去打工了,打工以后有的是机会,不差这三个月
力扣解法汇总473-火柴拼正方形
Introduction to program environment and preprocessing C language (advanced level)
力扣解法汇总868-二进制间距
力扣解法汇总1022-从根到叶的二进制数之和
Force deduction solution summary 1728- cat and mouse II
Navicat for MySQL 11 Linux cracking method
How to make div 100% page (not screen) height- How to make a div 100% of page (not screen) height?