题目链接: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 :
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) .
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
Source
Recommend
解析: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;
}