Counting Divisors HDU - 6069

In mathematics, the function d(n)d(n) denotes the number of divisors of positive integer nn. 

For example, d(12)=6d(12)=6 because 1,2,3,4,6,121,2,3,4,6,12 are all 1212's divisors. 

In this problem, given l,rl,r and kk, your task is to calculate the following thing : 

(∑i=lrd(ik))mod998244353(∑i=lrd(ik))mod998244353

 

Input

The first line of the input contains an integer T(1≤T≤15)T(1≤T≤15), denoting the number of test cases.

In each test case, there are 33 integers l,r,k(1≤l≤r≤1012,r−l≤106,1≤k≤107)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 HDU - 6069_第1张图片

题解:上图来自https://blog.csdn.net/protecteyesight/article/details/76685920

所以只需打表10e6内的素数,再由素数去求l~r,最后相加取余。

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define PI 3.14159265358979323
#define inf 0x3f3f3f3f
#define mod 998244353
using namespace std;
ll f[1001000],k=0,book[1001000];
ll a[1000100],b[1000100];
void lin()
{
    book[1]=1;
    for(int i=2; i<=1000000; i++)
    {
        if(!book[i])
        {
            f[k++]=i;
            for(int j=i*2; j<=1000000; j+=i)
                book[j]=1;
        }
    }
}

int main()
{
    lin();
    int t;
    scanf("%d",&t);
    while(t--)
    {
        ll l,r,tk;
        scanf("%lld%lld%lld",&l,&r,&tk);
        ll i,j;
        for(i=0; i<=r-l; i++)
        {
            a[i]=1;///储存相乘得数,初值为1
            b[i]=i+l;
        }
        for(i=0; i1)///说明10e6内的素数分解不了
                a[i]=a[i]*(tk+1)%mod;
            sum=(sum+a[i])%mod;
        }
        printf("%lld\n",sum);
    }
    return 0;
}

 

你可能感兴趣的:(Counting Divisors HDU - 6069)