The Preliminary Contest for ICPC Asia Xuzhou 2019 H.function(min25筛)

题目

思路来源

https://blog.csdn.net/jk_chen_acmer/article/details/101558425

题解

min25筛的部分用的比较基础,用了一个区间素数个数,一个区间素数和

首先,考虑这个式子,阶乘的话,1被计了n次,2被计了n-1次,i被计了n+1-i次

则答案等价于求\sum_{i=1}^{n}(n+1-i)f(i),即(n+1)\sum_{i=1}^{n}f(i)-\sum_{i=1}^{n}i*f(i)

 

f函数,实际上等价于统计每个p出现了多少次,最后求个总和,

考虑勒让德定理,统计每个p^{e}出现了多少次,\sum_{i=1}^{n}f(i)=\sum_{p^{e}}\left \lfloor \frac{n}{p^{e}} \right \rfloor

g(i)=i*f(i),对于p^{e}的每个倍数k*p^{e},其对答案的贡献都是k*p^{e}

所以提一个p^{e}出来等差数列求和,即知这部分最终答案为\sum_{i=1}^{n}i*f(i)=\sum_{p^{e}}\frac{\left \lfloor \frac{n}{p^{e}} \right \rfloor*(\left \lfloor \frac{n}{p^{e}}\right \rfloor+1)}{2}p^{e}

暴力的做的话,从1往上枚举幂次e至超出限制,累加答案即可,但复杂度不大行,

所以,对于e>=2的p^{e},由于此时p\leq \sqrt n,暴力枚举p统计上述的f和g,

 

而对于e=1的情形,需要数论分块解决[l,r]区间内的素数和、素数个数,

此时,套一下min25筛的质数处理部分,前缀和作差即可

代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e5+10,mod=998244353,inv2=(mod+1)/2;
ll n,Sqr,w[N],ans,ret;
ll pri[N],id1[N],id2[N],h[N],g[N],c;
bool zs[N];
int tot,sp[N];
void pre(int n){
	zs[1]=true;
	for(int i=2;i<=n;++i){
		if(!zs[i]){
            pri[++tot]=i;
            sp[tot]=(sp[tot-1]+i)%mod;
		}
		for(int j=1;j<=tot&&i*pri[j]<=n;++j){
			zs[i*pri[j]]=true;
			if(i%pri[j]==0)break;
		}
	}
}
int main(){
	scanf("%lld",&n);
	Sqr=sqrt(n);
	pre(Sqr);
	for(ll l=1,r;l<=n;l=r+1){
		r=n/(n/l);w[++c]=n/l;
		h[c]=(w[c]-1)%mod;
		g[c]=(w[c]%mod)*((w[c]+1)%mod)%mod*inv2%mod-1;
		if(w[c]<=Sqr)id1[w[c]]=c;
		else id2[r]=c;
	}
	for(int j=1;j<=tot;++j){
		for(int i=1;i<=c && pri[j]*pri[j]<=w[i];++i){
			int k=(w[i]/pri[j]<=Sqr)?id1[w[i]/pri[j]]:id2[n/(w[i]/pri[j])];
			(g[i]-=1ll*pri[j]*(g[k]-sp[j-1])%mod)%=mod;
			(h[i]-=h[k]-j+1)%=mod;
		}
	}
    /*
    for(ll l=1,r;l<=n;l=r+1){
        r=n/(n/l);
        ll x=(n/l)%mod;
        ans=(ans+x)%mod;
    }
    ans=(ans-n%mod+mod)%mod;
    */
    for(int j=1;j<=tot && pri[j]*pri[j]<=n;++j){//枚举p<=sqrt(n)
        for(ll t2=pri[j]*pri[j];t2<=n;t2*=pri[j]){//枚举p的幂次e>=2
            ll v=(n/t2)%mod,v2=v+1;
            ans=(ans+(v*v2/2)%mod*t2%mod)%mod;
            ret=(ret+v)%mod;
        }
    }
    int pre=0,now=0;//[l,r]区间段求素数个数 求素数区间和 nowr-prer
    for(ll l=1,r;l<=n;l=r+1){
        r=n/(n/l);
        if(r<=Sqr)now=id1[r];
		else now=id2[n/r];

		ll v=(n/l)%mod,v2=v+1;
		ll sump=(g[now]-g[pre])%mod,nump=(h[now]-h[pre])%mod;
        //printf("l:%lld r:%lld sump:%lld nump:%lld now:%d pre:%d wnow:%lld wpre:%lld\n",l,r,sump,nump,now,pre,w[now],w[pre]);
        ans=(ans+(v*v2/2%mod)*sump%mod+mod)%mod;
        ret=(ret+(v%mod)*nump%mod+mod)%mod;
        pre=now;
    }
    printf("%lld\n",((n+1)%mod*ret-ans+mod)%mod);
	return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Sure, I'd be happy to give you some ideas for organizing a speech contest. Here are some suggestions: 1. Determine the theme and rules: Decide on the theme of the contest and the rules for participants. Will it be an open topic, or will there be a specific theme? What is the maximum length of the speech? Will there be any specific guidelines for language or content? 2. Decide on the judging criteria: Determine how the speeches will be evaluated. Will judges be looking for content, delivery, or both? Will there be a score sheet or rubric that judges will use to score the speeches? 3. Recruit judges: Find people who are qualified to judge the speeches. Ideally, they should have experience in public speaking or have a background in the theme of the contest. 4. Promote the contest: Advertise the contest to potential participants, such as students, professionals, or members of a specific community. Use social media, flyers, and other methods to get the word out. 5. Registration and selection: Set a deadline for registration and selection of participants. Consider having a preliminary round to narrow down the field before the final competition. 6. Prepare the venue: Ensure that the venue is suitable for the contest. Make sure that there is adequate seating, sound equipment, and lighting for the speakers. 7. Hold the contest: Set a date and time for the contest, and make sure that all participants and judges are aware of the schedule. Encourage audience participation and provide refreshments. 8. Award ceremony: After the contest, hold an award ceremony to recognize the winners and participants. Provide certificates or other prizes to the top performers. I hope these ideas help you in organizing a successful speech contest!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Code92007

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值