P3935 Calculating

题目描述

若xx分解质因数结果为(x=p_1^{k_1}p_2^{k_2}cdots p_n^{k_n}),令(f(x)=(k_1+1)(k_2+1)cdots (k_n+1)),求(sum_{i=l}^r)对998244353取模的结果。


(f(x)=(k_1+1)(k_2+1)cdots (k_n+1))看起来有点眼熟啊

这不就是因数个数嘛!!

首先定义$$f(x)=sum_{i=1}^xd(i)=sum_{i=1}^xlfloorfrac{x}{i} floor$$

那么(ans=f(r)-f(l-1))

除法分块一下就是(O(sqrt{n}))的!!


#include<iostream>
#include<cstdio>
#include<cstring>
#define N 998244353
#define LL long long
using namespace std;
LL n,m,L,R;
int main()
{
	scanf("%lld%lld",&n,&m);
	n-=1;
	for(LL l=1,r;l<=n;l=r+1)
	{
		r=n/(n/l);
		L+=(n/l)*(r-l+1)%N;
	}	
	for(LL l=1,r;l<=m;l=r+1)
	{
		r=m/(m/l);
		R+=(m/l)*(r-l+1)%N;
	}
	printf("%lld",((R-L)%N+N)%N);
}

luogu有100个测试点克海星

原文地址:https://www.cnblogs.com/ZUTTER/p/10241397.html