Counting Divisors

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1604    Accepted Submission(s): 592

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
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6079 6078 6077 6076 6075 
/*
* @Author: Lyucheng
* @Date: 2017-08-03 13:13:45
* @Last Modified by: Lyucheng
* @Last Modified time: 2017-08-04 11:25:19
*/
/*
题意:给你一个区间[l,r]让你求区间内每个数的k次方因子数的总和 思路:比赛的时候想出来 i^k的因子是 (n1*k+1)*(n2*k+1)*...*(np*k+1),但是没想出来怎么优化,素数枚举
很烦,四场比赛每次差一点,比赛的时候想的是枚举[l,r]之间的数,优化到8300ms,实在没法优化了,应
该反过来想,枚举从[l,r]的素因子,因为i素因子的个数远小于i,大多数在sqrt i内,最多只有一个在sqrt i
之外。
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> #define LL long long
#define mod 998244353
#define MAXN 1000005 using namespace std; int t;
LL l,r,k;
LL res;
LL d[MAXN];
LL pos[MAXN];
bool prime[MAXN];
LL p[MAXN];
int tol;
void init(){
tol=;
for(int i=;i<MAXN;i++){
prime[i]=true;
}
prime[]=prime[]=false;
for(int i=;i<MAXN;i++){
if(prime[i])
p[tol++]=(LL)i;
for(int j=;j<tol&&i*p[j]<MAXN;j++){
prime[i*p[j]]=false;
if((LL)i%p[j]==) break;
}
}
} int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
init();
scanf("%d",&t);
while(t--){
res=;
scanf("%I64d%I64d%I64d",&l,&r,&k);
for(LL i=l;i<=r;i++){
d[(int)(i-l)]=;
pos[(int)(i-l)]=i;
}
for(int i=;i<tol;i++){//枚举所有的素数
if(p[i]<=) continue;
LL cnt=(l+p[i]-)/p[i]*p[i];//找出[l,r]区间内的第一个p[i]的倍数
if(cnt-l<||cnt-l>r-l) continue;
for(int j=cnt-l;j<=r-l;j+=p[i]){
LL cur=;
while(pos[j]&&pos[j]%p[i]==){
cur++;
pos[j]/=p[i];
}
d[j]*=(cur*k+);
d[j]%=mod;
}
}
for(int i=;i<=r-l;i++){
if(pos[i]==)
res+=d[i];
else
res+=d[i]*(k+);
res%=mod;
}
printf("%I64d\n",res);
}
return ;
}

最新文章

  1. Windows Server 2012 虚拟化实战:网络(二)
  2. php导出EXCEL方法
  3. linux系统的常用命令
  4. ucos-内存管理:
  5. BZOJ_3224_普通平衡树_(Treap)
  6. P - Atlantis - hdu1542(求面积)
  7. JSON入门之二:org.json的基本用法
  8. VS2010/MFC对话框:一般属性页对话框的创建及显示
  9. jacksonall的使用,解析json
  10. JVM学习(1)——通过实例总结Java虚拟机的运行机制(转)
  11. 一个初学者的辛酸路程-FTP-9
  12. JavaScript的基础学习
  13. pypinyin, jieba分词与Gensim
  14. 盒模型、position、float详解css重点汇总
  15. 移动端上拉加载,下拉刷新效果Demo
  16. [administrator] rpmbuild
  17. 剑指offer十五之反转链表
  18. js读取本地txt文件中的json数据
  19. XMLTransformProvider
  20. MySQL 、SQL MS Access、和 SQL Server 数据类型

热门文章

  1. android动画的实现过程
  2. 跨Storyboard调用
  3. 微服务~Eureka实现的服务注册与发现及服务之间的调用
  4. 逆向实用干货分享,Hook技术第一讲,之Hook Windows API
  5. 大数据 - Teradata学习体会
  6. vue-ajax小封装
  7. ubuntu12.04添加程序启动器到Dash Home
  8. Linux入门之常用命令(6)Bash命令重定向 管线命令
  9. MySQL Base
  10. HDU2066 一个人的旅行 最短路基础