[HDU 6069] Counting Divisors

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 :

\[ \left(\sum_{i=l}^rd(i^k)\right)\bmod 998244353 \]

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≤10^{12},r−l≤10^6,1≤k≤10^7)\).

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

2017 Multi-University Training Contest - Team 4

Solution

\(i=p_1^{a_1}p_2^{a_2}\cdots p_n^{a_n}\),有 \(d(i)=(1+a_1)(1+a_2)\cdots(1+a_n),d(i^k)=(1+k\cdot a_1)(1+k\cdot a_2)\cdots(1+k\cdot a_n)\)

\(1\cdots\sqrt r\) 枚举质数,用每个质数筛 \(l\cdots r\)

Code

#include <cstdio>
#include <cmath>

typedef long long LL;
const int N = 1000005, mod = 998244353;
int p[N], np[N], tot, f[N]; long long g[N];

int read() {
    int x = 0; char c = getchar();
    while (c < '0' || c > '9') c = getchar();
    while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
    return x;
}
void sieve(int n) {
    for (int i = 2; i <= n; ++i) {
        if (!np[i]) p[++tot] = i;
        for (int j = 1; j <= tot && i * p[j] <= n; ++j) {
            np[i * p[j]] = 1;
            if (i % p[j] == 0) break;
        }
    }
}
int main() {
    sieve(1000000);
    for (int T = read(); T; --T) {
        LL l, r; scanf("%lld%lld", &l, &r);
        int k = read(), m = sqrt(r), ans = 0;
        for (int i = 1; i <= r - l + 1; ++i) f[i] = 1, g[i] = i + l - 1;
        for (int i = 1; i <= tot && p[i] <= m; ++i) {
            LL x = p[i] < l ? (l + p[i] - 1) / p[i] * p[i] : p[i];
            for (LL j = x; j <= r; j += p[i]) {
                int t = 1;
                while (g[j - l + 1] % p[i] == 0) {
                    if ((t += k) >= mod) t -= mod;
                    g[j - l + 1] /= p[i];
                }
                f[j - l + 1] = 1LL * f[j - l + 1] * t % mod;
            }
        }
        for (int i = 1; i <= r - l + 1; ++i) {
            if (g[i] > 1) f[i] = (1LL + k) * f[i] % mod;
            if ((ans += f[i]) >= mod) ans -= mod;
        }
        printf("%d\n", ans);
    }
    return 0;
}

转载于:https://www.cnblogs.com/fly-in-milkyway/p/10384321.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值