[洛谷3935]Calculating
题目链接:https://www.luogu.org/problemnew/show/P3935
首先显然有\(\sum\limits_{i=l}^rf(i)=\sum\limits_{i=1}^rf(i)-\sum\limits_{i=1}^{l-1}f(i)\),于是问题转化为了如何求\(\sum\limits_{i=1}^nf(i)\),即\(\sum\limits_{i=1}^n\sum\limits_{d|i}1\),调整枚举顺序有\(\sum\limits_{d=1}^n\sum\limits_{i=1}^{\lfloor\frac{n}{d}\rfloor}1\),即\(\sum\limits_{d=1}^n\lfloor\dfrac{n}{d}\rfloor\),由于\(n\)很大,所以我们使用整除分块即可
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
static char buf[1000000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
int x=0,f=1; char ch=gc();
for (;ch<'0'||ch>'9';ch=gc()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=gc()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline int read(){
int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline void print(int x){
if (x<0) putchar('-'),x=-x;
if (x>9) print(x/10);
putchar(x%10+'0');
}
const int p=998244353;
int solve(ll n){
int res=0;
for (ll i=1,pos;i<=n;i=pos+1){
pos=n/(n/i); int len=(pos-i+1)%p;
res=(res+1ll*len*(n/i)%p)%p;
}
return res;
}
int main(){
ll l,r;
scanf("%lld%lld",&l,&r);
printf("%d\n",(solve(r)-solve(l-1)+p)%p);
return 0;
}