地址:http://acm.split.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): 1235    Accepted Submission(s): 433

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
 

思路:

  首先需要知道:一个数可以用唯一分解定理表示成:n=p1^a1*p2^2......*pn^an

         质约数个数为(a1+1)*(a2+1)*....*(an+1)

  那么n^k的质约数个数为(a1*k+1)*(a2*k+1)*.....*(an*k+1)

  所以这题的关键是求l,r区间每个数的质约数有那些,且次数是多少。

  考虑到:l,r最大为1e12,所以枚举1-1e6内的所有素数后即可知道l,r中每个数的质约数有哪些,同时可以知道次数是多少

  但是直接在1-1e6的素数表内查找l,r中的某个数的素约数的时间复杂度是O(1e6),显然不可行。

  所以可以通过线性筛的思想来求:对于1-1e6的素数,考虑他会在l,r内筛掉哪些数即可。

  因为1e12每个数最多有20左右的质约数,所以时间复杂度是O((r-l)*20)+O(1e5)(质数表大小)

  

 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=; LL ql,qr,qk,cnt,ls[K],sum[K],pr[K];
bool pa[K];
void init(void)
{
for(int i=;i<=;i++)
if(!pa[i])
{
pr[cnt++]=i;
for(int j=i*;j<=;j+=i) pa[j]=;
}
}
LL sc(int t)
{
LL ans=;
for(LL i=ql;i<=qr;i++) sum[i-ql]=,ls[i-ql]=i;
for(int i=;i<cnt;i++)
{
for(LL j=max(2LL,(ql+pr[i]-)/pr[i])*pr[i];j<=qr;j+=pr[i])
{
LL cnt=;
while(ls[j-ql]%pr[i]==) ls[j-ql]/=pr[i],cnt++;
sum[j-ql]=(sum[j-ql]*(qk*cnt+))%mod;
}
}
for(LL i=ql;i<=qr;i++)
{
if(ls[i-ql]!=) sum[i-ql]=(sum[i-ql]*(qk+))%mod;
ans+=sum[i-ql];
if(ans>=mod) ans-=mod;
}
return ans;
} int main(void)
{
//freopen("in.acm","r",stdin);
int t;scanf("%d",&t);
init();
while(t--)
{
scanf("%lld%lld%lld",&ql,&qr,&qk);
printf("%lld\n",sc(t));
}
return ;
}

2017 Multi-University Training Contest - Team 4 hdu6069 Counting Divisors的更多相关文章

  1. 2017 Multi-University Training Contest - Team 4——HDU6069&&Counting Divisors

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6069 题目意思:首先解释一下d[n]这个函数表示n有多少个因子,百度一下可以知道这个函数是一个非完全积 ...

  2. 【2017 Multi-University Training Contest - Team 4】Counting Divisors

    [Link]:http://acm.hdu.edu.cn/showproblem.php?pid=6069 [Description] 定义d(i)为数字i的因子个数; 求∑rld(ik) 其中l,r ...

  3. 2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】

    FFF at Valentine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  4. 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】

    Dying Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  5. 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】

    CSGO Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  6. 2017 Multi-University Training Contest - Team 9 1002&&HDU 6162 Ch’s gift【树链部分+线段树】

    Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  7. 2017 Multi-University Training Contest - Team 9 1001&&HDU 6161 Big binary tree【树形dp+hash】

    Big binary tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  8. 2017 Multi-University Training Contest - Team 1 1003&&HDU 6035 Colorful Tree【树形dp】

    Colorful Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  9. 2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】

    Function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

随机推荐

  1. [转]谈谈Linux下动态库查找路径的问题

    http://blog.chinaunix.net/uid-23069658-id-4028681.html 学习到了一个阶段之后,就需要不断的总结.沉淀.清零,然后才能继续“上路”.回想起自己当年刚 ...

  2. 【NLP】course

    http://52opencourse.com/235/%E6%96%AF%E5%9D%A6%E7%A6%8F%E5%A4%A7%E5%AD%A6%E8%87%AA%E7%84%B6%E8%AF%AD ...

  3. python 获取网页编码格式

    f = urllib2.urlopen(url,timeout=10)data = f.read()    # decode the htmlcontentType = f.headers.get(' ...

  4. Boatloader的工作流程

    (1)第一节阶段的功能 1.硬件设备的初始化 2.载入u-boot第二阶段的代码到我们的RAM空间 3.设置好栈 4.跳转到第二阶段的代码入口 (2)第二阶段的功能 1.初始化本阶段所使用的硬件设备 ...

  5. Linux上查看和修改字符集

    author :headsen chen date: 2018-05-14  16:20:30 一·查看字符集 字符集在系统中体现形式是一个环境变量,看当前终端使用字符集的有以下几种方式: 1: 1 ...

  6. flask--简记

    Jinjia变量过滤器: safe 渲染值时不转义 capitalize 把值的首字母转换成大写,其他字母转换成小写 lower 把值转换成小写形式 upper 把值转换成大写形式 title 把值中 ...

  7. 3、二、c# 面向对像编程。类,结构、C# 数据类型(引用类型、值 类型、指针类型)、ref参数与out参数、方法的重载、静态类型与静态成员、继承与多态、委托与事件

    一.类 定义类使用class关键字. <access specifier> class class_name { // member variables 成员变量 <access s ...

  8. docker remote api enable in ubuntu

    现在使用docker作为开发环境,操作系统是ubuntu16.10,pycharm中使用remote interpreter,需要用到remote api,结果发现自己的原答案是针对ubuntu 14 ...

  9. 多线程入门-第六章-线程的调度与控制之join

    /* 线程合并:将指定的线程加入到当前线程,可以将两个交替执行的线程合并为顺序执行的线程,即单线程. 如在B线程中调用了A的join方法,则线程A执行完后,才会执行线程B. */ public cla ...

  10. C#、devExpress 的 给bandedGrid加菜单功能 :复制、粘贴的例子(转)

    C#.devExpress 的 给bandedGrid加菜单功能 :复制.粘贴的例子 CopyFromGrid PasteToGrid PasteNewRowsToGrid private void ...