Counting Divisors

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

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:  6119 6118 6117 6116 6115 
 
题目大意:

求   l<= t <=r,  求   对多有满足条件的t 的   d(t^k)=t^k的所有因子的个数    的总和
 
题解:
根据约数个数定理:n=p1^a1×p2^a2×p3^a3*…*pk^ak,n的约数的个数就是(a1+1)(a2+1)(a3+1)…(ak+1).
只要求1~1e6之间的素数,如果当某个数除完前面的素数的时候还!=1,那么那个数字就是>1e6的素数。
 
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<cstring>
#include<bits/stdc++.h> using namespace std;
const long long mod=;
long long ans,l,r,k,len;
int T;
long long f[],num[],a[];
void pre()
{
bool flag;
len=;
f[++len]=;
for(int i=;i<=1e6;i++)
{
flag=;
for(int j=;j<=sqrt(i);j++)
if (i%j==) {flag=; break;}
if (flag) f[++len]=i;
}
return;
} int main()
{
pre(); //预处理出1~1e6之间的素数
scanf("%d",&T);
for(;T>;T--)
{
scanf("%lld%lld%lld",&l,&r,&k);
for(int i=;i<=r-l;i++) {num[i]=; a[i]=i+l;} //num【i】表示 i 这个数的因子个数
ans=;
for(int i=;i<=len;i++)
{
long long s=(l/f[i])*f[i];
if (s<l) s+=f[i];
for(long long j=s;j<=r;j+=f[i])
{
long long w=;
while(a[j-l]%f[i]==)
{
a[j-l]/=f[i];
w++;
}
num[j-l]=num[j-l]*(w*k+)%mod;
}
}
for(int i=;i<=r-l;i++)
if (a[i]>) num[i]=num[i]*(k+)%mod; //特殊判断还剩下的数字!=1的情况,也就是还有一个大素数 for(int i=;i<=r-l;i++) ans=(ans+num[i])%mod;
printf("%lld\n",ans);
}
return ;
}

最新文章

  1. 用户故事驱动的敏捷开发 – 2. 创建backlog
  2. 第六百一十天how can I 坚持
  3. C#学习笔记----AppDomain应用程序域
  4. CentOS7配置双网卡绑定
  5. Ext comboBox的remote和local的区别
  6. Ubuntu12.10 下搭建基于KVM-QEMU的虚拟机环境(十六)
  7. android.content.Context 含义及使用
  8. IE兼容问题
  9. EffectiveC#7--选择恒定的原子值类型数据
  10. js实现页面图片加载进度条
  11. Eclipse上Spring-tool的安装
  12. java中的几个概念
  13. 黄聪:OTP动态密码_Java代码实现
  14. python爬取酒店信息练习
  15. MVC C# JS根据后台传入对象设置
  16. SSH公钥登录且禁止密码登录及更改默认端口
  17. 在Maprecue中利用MultipleOutputs输出多个文件
  18. java.lang.OutOfMemoryError: Java heap space 解决方法
  19. ajax跨域问题解决方案
  20. 插上翅膀,让Excel飞起来——xlwings(一)

热门文章

  1. JavaScript中的BOM和DOM
  2. nuxtjs中使用axios
  3. word之选中文本
  4. 配置 ROS 的 apt 源
  5. Android-Gradle(一)
  6. flask 在视图函数里操作数据库
  7. MongoDB集群单mongos的问题总结
  8. h5 的localStorage和sessionStorage存到缓存里面的值是string类型
  9. L2-025. 分而治之
  10. c++: internal compiler error: Killed