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

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

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

#include<stdio.h>
#include<map>
#include<set>
#include<stdio.h>
#include<string.h>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<queue>
#include<math.h>
#include<iostream>
#include<algorithm>
#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; i<k; i++)
        {
            ll x=l/f[i]*f[i];///x是从l开始,第一个能整除f[i]的数
            if(x<l)
                x+=f[i];
            for(j=x; j<=r; j+=f[i])
            {
                int w=0;
                while(b[j-l]%f[i]==0)
                {
                    w++;
                    b[j-l]/=f[i];
                }
                a[j-l]=a[j-l]*(w*tk+1)%mod;
            }
        }
        ll sum=0;
        for(i=0; i<=r-l; i++)
        {
            if(b[i]>1)///说明10e6内的素数分解不了
                a[i]=a[i]*(tk+1)%mod;
            sum=(sum+a[i])%mod;
        }
        printf("%lld\n",sum);
    }
    return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值