# HDU 6069 Counting Divisors

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


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

typedef long long LL;
const int mod = 998244353;
const int maxn = 1e6 + 500;
int pri[maxn];
LL a[maxn],b[maxn];
bool vis[maxn];
LL r,l,k;
int  num;

void prime(){
memset(vis,false , sizeof(vis));
num = 0;
for(int  i = 2; i < maxn ; ++i){
if(!vis[i]) pri[++num] = i;
for(int j = 1; j <= num && i * pri[j] < maxn; ++j){
vis[ i * pri[j]]  = true;
if (i % pri[j] == 0) break;
}
}
}

int main()
{
int T;
prime();
//freopen("1003.in", "r", stdin);
// freopen("1003.txt", "w", stdout);
scanf("%d", &T);
while (T--)
{
LL ans = 0;
scanf("%lld %lld %lld", &l, &r, &k);
for(LL i = l; i <= r; ++i){
a[i - l] = 1;
b[i - l] = i;
}for(int  i = 1 ; i <= num && pri[i] <= (int)sqrt((double) r); ++i){// 枚举素数.
LL t = l / pri[i] * pri[i];//在 l 到 r 内处理这个素数的倍数.
while(t < l) t += pri[i];
while(t <= r){
int cnt = 0;
while(b[t-l] % pri[i] == 0){
b[t-l] /= pri[i];
cnt++;
}a[t-l]  = (a[t-l] *(k * cnt + 1)) % mod;//储存每个数对应的因子个数.
t += pri[i];
}
}for(LL i = l; i <= r; ++i)
if(b[i-l] == 1)
ans = (ans + a[i-l]) % mod;
//否则这个数还是个素数.
else ans = (ans + a[i-l]*(k + 1) % mod) % mod;
printf("%lld\n",ans);
}
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120