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. 统计Git

    公司需求统计Mos代码行数 方法一:用git #!/bin/bash read -p "输入你要统计mos的分支:" branch Mos_Project=(uusafe-prod ...

  2. Codeforces 1110C (思维+数论)

    题面 传送门 分析 这种数据范围比较大的题最好的方法是先暴力打表找规律 通过打表,可以发现规律如下: 定义\(x=2^{log_2a+1}\) (注意,cf官方题解这里写错了,官方题解中定义\(x=2 ...

  3. k8s入门教程

    1. k8s概述 Kubernetes(简称K8S) 是Google开源的分布式的容器管理平台,方便我们在服务器集群中管理我们容器化应用. 教程主要介绍怎么使用阿里云容器服务(kubernetes版本 ...

  4. k8s常用笔记

    安装docker // 安装docker $ yum install -y docker-ce // 开机启动 && 启动服务 $ systemctl enable docker &a ...

  5. DevExpress 控件中设置分隔符

    原文:DevExpress 控件中设置分隔符 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net ...

  6. go中布尔类型bool的用法

    示例 // bool布尔类型的用法 package main import ( "fmt" "unsafe" ) func main() { // bool类型 ...

  7. elasticsearch 深入 —— Post Filter后置过滤器

    过滤查询以及聚合 A natural extension to aggregation scoping is filtering. Because the aggregation operates i ...

  8. Backend事后诸葛亮

    事后诸葛亮 设想和目标 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 我们的软件想解决初学编程语言的入门困难.定义的不算太清楚,没有仔细地调查用户入门的困难之处. ...

  9. python 子类继承父类__init__(转载)

    转载: http://www.jb51.net/article/100195.htm 前言 使用Python写过面向对象的代码的同学,可能对 __init__ 方法已经非常熟悉了,__init__方法 ...

  10. shell条件判断命令test