Problem Description
In mathematics, the function
d(n)
denotes the number of divisors of positive integer
n
.
For example, d(12)=6 because 1,2,3,4,6,12 are all 12 's divisors.
In this problem, given l,r and k , your task is to calculate the following thing :
For example, d(12)=6 because 1,2,3,4,6,12 are all 12 's divisors.
In this problem, given l,r and k , your task is to calculate the following thing :
(∑i=lrd(ik))mod998244353
Input
The first line of the input contains an integer
T(1≤T≤15)
, denoting the number of test cases.
In each test case, there are 3 integers l,r,k(1≤l≤r≤1012,r−l≤106,1≤k≤107) .
In each test case, there are 3 integers l,r,k(1≤l≤r≤1012,r−l≤106,1≤k≤107) .
Output
For each test case, print a single line containing an integer, denoting the answer.
Sample Input
3 1 5 1 1 10 2 1 100 3
Sample Output
10 48 2302
注意到r-l<=10^6
所以我们考虑把l到r之间的所有数都分解质因数
如果一个个枚举的话复杂度是sqrt的,无法接受
因此我们考虑枚举每一个质因数对每个位置的贡献,这样复杂度就是log级别的了
最后k次方我们只要考虑把每个质因数个数翻k倍即可
如果p=2^x1*3^x2*……^z^xn
那么约数个数即为(x1+1)(x2+1)……(xn+1)
#include<map>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<cassert>
#include<iostream>
#include<algorithm>
using namespace std;
long long mod=998244353;
int mu[1000101],fai[1000101];
long long f[1000101];
long long prime[1000101];//mu莫比乌斯 fai欧拉
bool check[1000101];
int n,tot;
inline void findfai()
{
memset(check,false,sizeof(check));
fai[1]=1; mu[1]=1;
int i,j;
for(i=2;i<=1000000;i++)
{
if(!check[i])
{
tot++;
prime[tot]=i;
fai[i]=i-1; mu[i]=-1;
}
for(j=1;j<=tot;j++)
{
if(i*prime[j]>1000000)
break;
check[i*prime[j]]=true;
if(i%prime[j]==0)
{
fai[i*prime[j]]=fai[i]*prime[j]; mu[i*prime[j]]=0;
break;
}
else
fai[i*prime[j]]=fai[i]*(prime[j]-1); mu[i*prime[j]]=-mu[i];
}
}
}
long long a[1000101];
int main()
{
findfai();
int T;
scanf("%d",&T);
while(T>0)
{
T--;
long long l,r,k;
scanf("%lld%lld%lld",&l,&r,&k);
int i;
long long j;
// memset(f,0,sizeof(f));
for(i=1;i<=r-l+1LL;i++)
{
f[i]=1;
a[i]=(long long)i+l-1LL;
}
for(i=1;i<=tot;i++)
{
long long ll=((l-1LL)/prime[i]+1LL)*prime[i];
for(j=ll;j<=r;j+=prime[i])
{
int sum=0;
while(a[j-l+1]%prime[i]==0)
{
sum++;
a[j-l+1]/=prime[i];
}
f[j-l+1]=f[j-l+1]*((long long)sum*k+1LL)%mod;
}
}
for(i=1;i<=r-l+1;i++)
if(a[i]!=1)
f[i]=f[i]*(k+1LL)%mod;
long long ans=0;
for(i=1;i<=r-l+1;i++)
ans=(ans+f[i])%mod;
printf("%lld\n",ans);
}
return 0;
}