Counting Divisors

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

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 :

 
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
 
题目大意:d(i)是 i 的因数个数,让我们求 l<=i<=r 时,d(i^k)之和.
思路:对一个数n=p1t1*p2t2*...*pntn, pi是n的质因数。则n的因数个数是(t1+1)*(t2+1)*...*(tn-1+1)*(tn+1), 易得i^k的因数个数是(k*t1+1)*(k*t2+1)*...*(k*tn+1),那么接下来就是要对 i 进行质因数分解了。 在打表打出质因数后,分解时对于一个质数P, 在[l , r]区间内所有能整除P的数进行质因数分解,这样能保证不会有多余时间花在搜索质因数上,这种做法类似筛法。具体见代码。
 
AC代码(标程):
 #include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<stdio.h>
#define it (p-l)
using namespace std;
typedef long long LL;
const LL MOD=;
const long long MAXN=;
long long prime[MAXN],tot=;
bool isPrime[MAXN];
LL k,num[MAXN],res[MAXN];
void getprime(){
memset(isPrime, true, sizeof(isPrime));
for(int i=;i<MAXN;i++){
if(isPrime[i]){
prime[++tot]=i;
}
for(int j=;j<=tot;j++){
if(i*prime[j]>MAXN) break;
isPrime[i*prime[j]]=false;
if(i%prime[j]==) break;
}
}
return ;
}
LL cal(LL l, LL r)
{
LL ans=,tmp,cnt;
for(int i=;i<=tot;i++)
{
LL p=(l+prime[i]-)/prime[i]*prime[i];
while(p<=r){
cnt=;
while(num[it]%prime[i]==){
num[it]/=prime[i];
cnt++;
}
res[it]=res[it]*(k*cnt+)%MOD;
p+=prime[i];
}
}
for(LL p=l;p<=r;p++){
if(num[it]==)
ans+=res[it];
else
ans+=res[it]*(k+);
ans%=MOD;
}
return ans;
}
int main()
{
int T;
LL l,r;
getprime();
scanf("%d", &T);
while(T--)
{
scanf("%lld %lld %lld", &l, &r, &k);
for(LL p=l;p<=r;p++){
res[it]=;
num[it]=p;
}
LL res=cal(l, r);
printf("%lld\n", res);
}
}

HDU 6069 Counting Divisors —— 2017 Multi-University Training 4的更多相关文章

  1. HDU 6069 Counting Divisors(2017 Multi-University Training Contest - Team 4 )

    Output For each test case, print a single line containing an integer, denoting the answer.   Sample ...

  2. HDU 6069 Counting Divisors

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  3. hdu 6069 Counting Divisors(求因子的个数)

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  4. hdu 6069 Counting Divisors 筛法

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  5. HDU 6069 Counting Divisors(唯一分解定理+因子数)

    http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...

  6. 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)

    题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...

  7. HDU 6069 Counting Divisors (素数+筛法)

    题意:给定 l,r,k,让你求,其中 l <= r <= 1e12, r-l <= 1e6, k <= 1e7. 析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选, ...

  8. HDU 6069 Counting Divisors(区间素数筛法)

    题意:...就题面一句话 思路:比赛一看公式,就想到要用到约数个数定理 约数个数定理就是: 对于一个大于1正整数n可以分解质因数: 则n的正约数的个数就是 对于n^k其实就是每个因子的个数乘了一个K ...

  9. hdu 6069 Counting divisors 公式+区间筛

    比赛的时候把公式扣出来了,,但是没有想到用筛法算公因子,,默默学习一下.. 题解:设n=p1^(c1)p2^{c2}...pm^{cm},n=p​1^​c​1*​​​​p​2​^c​2​​​​...p ...

随机推荐

  1. 1.安装TypeScrpit

    https://www.tslang.cn/index.html 1.vs安装 之前网上的查的安装方法是先安装nodejs,之后执行 npm install -g typescript 但是从官网的下 ...

  2. linux使用apache发布静态html网页

    环境 centOS7+httpd 安装httpd 安装 #检查是否安装和httpd rpm -qa | grep httpd #如果没安装 yum -y install httpd 启动httpd并验 ...

  3. 用Delphi从内存流中判断图片格式[转]

    http://blog.163.com/tfn2008%40yeah/blog/static/110321319201222243214337/ 用Delphi从内存流中判断图片格式[转] 2012- ...

  4. 用C#调用C++DLL提示找不到DLL解决方法【转】

    用C#调用自己写的C++ DLL(x64),总是提示找不到DLL,调试可以,发布release老是提示找不到DLL(dll文件确定存在) 原因:Visual C++的DLL分发方式没选:调试默认选择: ...

  5. 本站页脚HTML回顶部代码

    <style type="text/css">.top { width: 50px; height: 50px; background-color: #F0F0F0; ...

  6. Fedora 的截屏功能

    写写博客少不了截图,Windows 上使用微信的快捷键 Ctrl+A 截图并且可以随意编辑是挺方便的,开始在 Linux 上还没有找到这样的软件,只找到了不支持编辑的简单截图软件. 1. 使用 Scr ...

  7. JS基础(上)

    JS与DOM的关系 浏览器有渲染html代码的功能,把html源码(如div,p标签等)在内存里形成一个DOM对象 文档对象模型DOM(Document Object Model)定义访问和处理HTM ...

  8. Docker 换源

    近几天又折腾起 docker来了    我发现自己在拉镜像的时候,总是超时    然后百度了一下  说要换源 90sec的一个水友 推荐了我 阿里云的加速源    我看了还是免费就想试一下 讲一下过程 ...

  9. 【xinsir】githook之precommit分享

    钩子类型 使用node编写githook,以pre-commit为例: 1.在项目下配置自动生成pre-commit文件,一般可以在启动项目的脚本下添加: modifyPreCommit: funct ...

  10. Linux服务正常启动,Linux服务器能访问,但是外部机器不能访问

    公司用到了jenkins,就在自己虚拟机里面部署了一个jenkins.部署成功之后,在Linux虚拟机里面能正常访问,但是外部真实机却不能访问.当时的第一反应就是觉得应该是权限问题,猜测会不会是jen ...