hdu 6069 Counting Divisors(2017多校第四场)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6069

Counting Divisors

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


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(1T15) , denoting the number of test cases.

In each test case, there are  3  integers  l,r,k(1lr1012,rl106,1k107) .
 

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
 

Source
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:   6143  6142  6141  6140  6139 
 

Statistic |  Submit |  Discuss |  Note

解析:n = k1^x1*k2^x2*........kn^xn, (k1, k2, k3.......kn是质数, x1, x2,z3.......xn是幂),那么一个数的因子数等于 ans = (x1+1)*(x2+1)*(x3+1)*......*(xn+1)。知道这样还不够,这样暴力写会TLE,咱还需要用到区间筛选,对,就是这样,打素数表时10^5会WA,需要打10^6的表,WA的心疼,,

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1000006;
const LL p = 998244353;
int pri[N], ispri[N], len;

LL a[1000009], num[1000009];

void init()
{
    memset(ispri, 0, sizeof(ispri));
    len = 0;
    for(int i = 2; i <= 1000000; i++)
    {
        if(ispri[i]) continue;
        pri[len++] = i;
        for(int j = i*2; j <= 1000000; j += i) ispri[j] = 1;
    }
}


int main()
{
    init();
    LL l, r, k;
    int t;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%lld%lld%lld", &l, &r, &k);
        for(int i = 0; i <= r - l; i++) a[i] = l+i, num[i] = 1;
        for(int i = 0; i < len; i++)
        {
            LL s = l/pri[i]*pri[i];
            if(s != l) s += pri[i];
            for(LL j = s; j <= r; j += pri[i])
            {
                LL w = 0;
                while(a[j-l] % pri[i] == 0) w++, a[j-l] /= pri[i];
                num[j-l] = num[j-l] * ((1LL*w*k+1) % p) % p;
            }
        }
        LL ans = 0;
        for(int i = 0; i <= r-l; i++) if(a[i] != 1) num[i] = (num[i] * (k + 1)) % p;
        for(int i = 0; i <= r-l; i++) ans = (ans + num[i]) % p;
        printf("%lld\n", ans);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值