Counting Divisors

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0

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 :

(∑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).

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
Counting Divisors_第1张图片

官方标称:

#include
typedef long long ll;
const int N=1000010,P=998244353;
int Case,i,j,k,p[N/10],tot,g[N],ans;
ll n,l,r,f[N];
bool v[N];
inline void work(ll p)
{
    for(ll i=l/p*p; i<=r; i+=p)if(i>=l)
        {
            int o=0;
            while(f[i-l]%p==0)f[i-l]/=p,o++;
            g[i-l]=1LL*g[i-l]*(o*k+1)%P;
        }
}
int main()
{
    for(i=2; iif(!v[i])p[tot++]=i;
        for(j=0; j*p[j]*p[j]]=1;
            if(i%p[j]==0)break;
        }
    }
    scanf("%d",&Case);
    while(Case--)
    {
        scanf("%lld%lld%d",&l,&r,&k);
        n=r-l;
        for(i=0; i<=n; i++)f[i]=i+l,g[i]=1;
        for(i=0; iif(1LL*p[i]*p[i]>r)break;
            work(p[i]);
        }
        for(ans=i=0; i<=n; i++)
        {
            if(f[i]>1)g[i]=1LL*g[i]*(k+1)%P;
            ans=(ans+g[i])%P;
        }
        printf("%d\n",ans);
    }
    return 0;
}

你可能感兴趣的:(暑期多校联合训练赛数据结构试题,数据结构与算法)