地址: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. 【mysql】windows7 安装 Mysql

    From: http://jingyan.baidu.com/article/e52e3615a1128c40c70c5174.html 安装(解压) ZIP Archive版是免安装的.只要解压就行 ...

  2. 【python】matplotlib中文乱码问题

    http://www.pythoner.com/200.html 改matplotlibrc文件进入Python安装目录下的Lib\site-packages\matplotlib\mpl-data目 ...

  3. jQuery实现瀑布流布局详解(PC和移动端)

    首先我们将如下样式的若干个单元写进body中,并将“box”向左浮动: <div class="box">  <img class="img" ...

  4. jQuery实现提交按钮点击后变成正在处理字样并禁止点击的方法

    本文实例讲述了jQuery实现提交按钮点击后变成正在处理字样并禁止点击的方法.分享给大家供大家参考.具体实现方法如下: 这里主要通过val方法设置按钮的文字,并用attr方法修改disabled属性实 ...

  5. CodeForces 558C Amr and Chemistry (位运算,数论,规律,枚举)

    Codeforces 558C 题意:给n个数字,对每一个数字能够进行两种操作:num*2与num/2(向下取整),求:让n个数相等最少须要操作多少次. 分析: 计算每一个数的二进制公共前缀. 枚举法 ...

  6. iOS 文件和数据管理 (可能会删除本地文件储存)

    转自:http://www.apple.com.cn/developer/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgramm ...

  7. oracle如何用sql查看触发器?

    ORACLE查出表所有的触发器及触发器详细信息 一.查all_triggers表得到trigger_name Sql代码 select trigger_name from all_triggers w ...

  8. window 发布已编译好的ASP文件到IIS

    1.进入window 7的控制面板,点击程序,选择程序和功能中的 打开或关闭Windows功能.安装IIS

  9. Hadoop入门必须知道的简单知识

    Hadoop入门知识 Hadoop构成 Hadoop由4个主要构成部分: 1) 基础核心:提供基础的通用的功能 2) HDFS:分布式存储 3) MapReduce:分布式计算 4) YARN:资源分 ...

  10. [iOS微博项目 - 4.2] - 设置转发微博背景

    github: https://github.com/hellovoidworld/HVWWeibo A.转发微博部分的淡灰色背景 1.需求 转发微博部分需要设置背景色 使用图片作为背景   2.思路 ...