topic
Rounded statistics
analysis
- For the first six test points, you can quickly sift out prime numbers with a linear sieve, and then calculate each point with the number theorem. For k, you can actually multiply cnt by k every time *cnt.
- Then the next four big data points will not work. If you can't filter out so many prime numbers, you won't be able to judge one by one by force.
- Think about it and discover that
r-l<=10^6
, and the prime number after r^2 can only appear once to the power or 0 times. - So you can screen out
sqrt(r)
prime numbers within the putl~r
all the numbers except violence, get that donesqrt(r)
after less than a few, if thel~r
number is still not 1, then they must be greater thansqrt(r)
the number of times a certain quality, it directly multiplied by the value of dk+1
can be.
program
#include <cstdio>
#define Ha 998244353
typedef long long ll;
ll l,r,k,N,d[1000005];
ll p[1000005],rest[1000005],num,ans;
bool f[1000005];
int main(){
scanf("%lld%lld%lld",&l,&r,&k); l--;
N=r-l;
for (ll i=l+1; i<=r; i++) d[i-l]=1,rest[i-l]=i;
for (ll x=2; x*x<=r; x++){
if (!f[x]){
p[++num]=x;
ll ytx=l/x*x+x,cnt;
for (cnt=0; ytx<=r; ytx+=x,cnt=0){
while (rest[ytx-l]%x==0)
rest[ytx-l]/=x,cnt++;
cnt=(cnt*k+1)%Ha;
d[ytx-l]=d[ytx-l]*cnt%Ha;
}
}
for (ll i=1; i<=num && x*p[i]<=1000000; i++) f[x*p[i]]=1;
}
for (ll i=l+1; i<=r; i++) if (rest[i-l]>1) d[i-l]=d[i-l]*(k+1)%Ha;
for (ll i=l+1; i<=r; i++) ans=(ans+d[i-l])%Ha;
printf("%lld",ans);
}