Counting Divisors
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) Total Submission(s): 1996 Accepted Submission(s): 728 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(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
Source
题意:求l到r中所有数的k次方的因数个数之和。
题解:
设n=p_1^{c_1}p_2^{c_2}...p_m^{c_m}n=p1c1p2c2...pmcm,则d(n^k)=(kc_1+1)(kc_2+1)...(kc_m+1)d(nk)=(kc1+1)(kc2+1)...(kcm+1),因为区间长度不超过1e6枚举不超过
r√ 的所有质数p,再枚举区间[l,r]中所有p 的倍数,将其分解质因数,最后剩下的部分就是超过 r√ 的质数,只可能是 0 个或 1 个,进行特判一下,将其加上就好了。注意:这里分解的时候不是把每一个数逐一进行分解,而是类似于区间两次筛,每一次枚举素数的倍数,然后整段的去筛计算素数的指数,相当于每次找len/2,len/3,len/4...len/n次,以节约时间,与的思路有异曲同工之妙。
写的时候傻逼了,把
for (int j = 2 * i; j < maxn; j += i) not_prime[j] = 1;
的not_prime[j] = 1写成了not_prime[i] = 1,T了一万年 (T_T)
#include#include #include #include #include #include #include