题目链接

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

分析:

如果一个数n可以分解成n=p1m1*p2m2*···*pn^mn的话(其中p1,p1···为素数),那么这个数的因子个数就为(m1+1)*(m2+1)*···*(mn+1)。

同样的,这个数由n变为nk的话,相应的次数前面分别乘以k即可。即nk的因子个数为(k*m1+1)*(km2+1)*···*(kmn+1)。

这个问题解决掉之后,我们会发现数据范围太大,我们的数组分本没办法开到那么大,我们可以把数据由前半部分来推出后半部分。

先打个1e6范围内的素数表,然后枚举可行范围内的每个素数,在区间[ l , r ]内寻找所有的该素数的倍数,将其分解质因数。

到最后如果一个数没有变成1,那就说明这个数是大于1e6的质数。(质数只有1和它本身)那么如果按照规律计算的话,只需要乘上一个(k+1)就行了。

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<cmath>
  4. using namespace std;
  5. typedef long long ll;
  6. const int maxn=1e6+5;
  7. const int mod=998244353;
  8. int n;
  9. int cnt=0;
  10. int primes[maxn];
  11. int vis[maxn];
  12. void get_primes()///筛选法求出1e6之内的素数,比1e6大的素数可以通过这些素数间接的求出来
  13. {
  14. int m=sqrt(maxn+0.5);///开方,循环到这个就行了
  15. for(int i=2; i<=m; i++)
  16. {
  17. if(!vis[i])
  18. {
  19. for(int j=i*i; j<=maxn; j+=i)
  20. vis[j]=1;
  21. }
  22. }
  23. for(int i=2; i<=maxn; i++)
  24. if(!vis[i]) primes[cnt++]=i;
  25. }
  26. ll l, r, k;
  27. ll sum[maxn], num[maxn];
  28. int main()
  29. {
  30. get_primes();
  31. int T;
  32. scanf("%d",&T);
  33. while(T--)
  34. {
  35. scanf("%lld%lld%lld",&l,&r,&k);
  36. ll ans=0;
  37. ///因为l和r的范围比较大,但是它们之间的差值不会查过1e6,可以将数组缩小一点
  38. for(ll i=l; i<=r; i++)
  39. {
  40. sum[i-l]=1;///个数
  41. num[i-l]=i;///表示的是这个数
  42. }
  43. for(int i=0; i<cnt && primes[i]*primes[i]<=r; i++)///所有的素数
  44. {
  45. ///求出的是[l,r]区间中第一个能够被rimes[i]整除的数
  46. ll tmp=ceil((long double)l/primes[i])*primes[i];
  47. for(ll j=tmp; j<=r; j+=primes[i])///枚举所有的这个素数的倍数
  48. {
  49. if(num[j-l]%primes[i]==0)
  50. {
  51. int res=0;
  52. while(num[j-l]%primes[i]==0)
  53. {
  54. res++;
  55. num[j-l]/=primes[i];
  56. }
  57. sum[j-l]=(sum[j-l]*(((ll)res*k+1))%mod)%mod;
  58. }
  59. }
  60. }
  61. for(ll i=l; i<=r; i++)
  62. {
  63. if(num[i-l]!=1)///那些本身是素数的数
  64. sum[i-l]=(sum[i-l]*(k+1))%mod; ///大于1e6的质数
  65. ans=(ans+sum[i-l])%mod;
  66. }
  67. printf("%lld\n",ans);
  68. }
  69. return 0;
  70. }

2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)的更多相关文章

  1. 2017ACM暑期多校联合训练 - Team 6 1003 HDU 6098 Inversion (模拟)

    题目链接 Problem Description Give an array A, the index starts from 1. Now we want to know Bi=maxi∤jAj , ...

  2. 2017ACM暑期多校联合训练 - Team 3 1003 HDU 6058 Kanade's sum (模拟)

    题目链接 Problem Description Give you an array A[1..n]of length n. Let f(l,r,k) be the k-th largest elem ...

  3. 2017ACM暑期多校联合训练 - Team 1 1003 HDU 6035 Colorful Tree (dfs)

    题目链接 Problem Description There is a tree with n nodes, each of which has a type of color represented ...

  4. 2017ACM暑期多校联合训练 - Team 2 1003 HDU 6047 Maximum Sequence (线段树)

    题目链接 Problem Description Steph is extremely obsessed with "sequence problems" that are usu ...

  5. 2017ACM暑期多校联合训练 - Team 4 1004 HDU 6070 Dirt Ratio (线段树)

    题目链接 Problem Description In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the foll ...

  6. 2017ACM暑期多校联合训练 - Team 9 1005 HDU 6165 FFF at Valentine (dfs)

    题目链接 Problem Description At Valentine's eve, Shylock and Lucar were enjoying their time as any other ...

  7. 2017ACM暑期多校联合训练 - Team 9 1010 HDU 6170 Two strings (dp)

    题目链接 Problem Description Giving two strings and you should judge if they are matched. The first stri ...

  8. 2017ACM暑期多校联合训练 - Team 8 1006 HDU 6138 Fleet of the Eternal Throne (字符串处理 AC自动机)

    题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion ...

  9. 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)

    题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...

随机推荐

  1. CentOS7 修改分辨率

    1. 修改文件: vi /boot/grub2/grub.cfg 2. 在linux16 开头的哪一行 增加 vga=0x341 修改为1024x768 3. 重启..

  2. 简单的 php 防注入、防跨站 函数

    /** * 简单的 php 防注入.防跨站 函数 * @return String */ function fn_safe($str_string) { //直接剔除 $_arr_dangerChar ...

  3. [LeetCode] Search in Rotated Array II

    Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...

  4. Graph-Based image segmentation method

    1.Graph-Based 方法简介 基于图的图像分割方法将图像伪造成带权值无向图的形式 : G = (V, E) 其中,V是顶点集合,把图像中的每个像素或者每个区域看成图的一个顶点:E是边的集合,连 ...

  5. 当使用listIterator进行迭代时候 list的迭代器可以在创建迭代器对象后 添加数据 但打印的时候不显示添加后的数据。 collection 的iterator迭代器不能添加数据 。list的对象与collection的实例对象都不能在创建迭代器后添加数据 list的迭代器保存的是循环前的数据长度

  6. robot framework 安装

    一.安装 Python 2.7 pip 和 setuptools (Python 的套件管理程式,最新版的Python 2.7.13已包含) Robot Framework (此工具本身) wxPyt ...

  7. Class类是什么? Class.forName()是干什么的?

    Class类概念 Class类用来描述一个类的结构,比如描述一个类有哪些成员,有哪些方法等.有多种方法可以获取一个类对应的Class类实例,比如: //第一种方式获取描述Dog类结构的Class类实例 ...

  8. ZJOI2012网络 题解报告【LCT】

    题目描述 有一个无向图G,每个点有个权值,每条边有一个颜色.这个无向图满足以下两个条件: 对于任意节点连出去的边中,相同颜色的边不超过两条. 图中不存在同色的环,同色的环指相同颜色的边构成的环. 在这 ...

  9. POJ.3087 Shuffle'm Up (模拟)

    POJ.3087 Shuffle'm Up (模拟) 题意分析 给定两个长度为len的字符串s1和s2, 接着给出一个长度为len*2的字符串s12. 将字符串s1和s2通过一定的变换变成s12,找到 ...

  10. 洛谷P1943 LocalMaxima_NOI导刊2009提高(1)(分段打表)

    显然只需要算出每个数比前面所有数大的期望然后全部加起来就好了,一个数的期望怎么算呢? 对于一个数我们需要考虑比它大的数,因为比它小的数放它前面放它后面都可以,但是比它大的数只能放它后面.考虑大于等于它 ...