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. day46----JavaScript的函数及对象小结

    一:函数 01:普通函数 function f1(){ console.log("Helleo world") } f1(); //调用函数 -->Helleo world ...

  2. GitLab 安装,配置及维护

    参考: GitLab 官方文档 docker-gitlab,通过 docker-compose 快速安装 GitLab rake,是 Rails 的工具,类似 ruby 中常用的的 make.通过 R ...

  3. (appium+python)UI自动化_07_app UI自动化实例【叮咚搜索加车为例】

    前言 初学UI自动化的小伙伴,在配置好appium+python自动化环境后,往往不知道如何下手实现自动化.小编在初期学习的时候也有这种疑惑,在此以叮咚买菜app-搜索加车为实例,展示下appium是 ...

  4. 浅谈JSONObject解析JSON数据

    我们在做jmeter接口测试时能会用beanshell断言,一般都会将返回值转成JSONObject对象进行处理.本文选取较为复杂json格式数据,也将适用于java接口测试. JSON数据 { &q ...

  5. Java单链表

    一.概述 二.主方法 //创建头结点 private HeroNode head = new HeroNode(-1,null,null); //计数器,用于id的自增 private static ...

  6. Codeforces 1091C (数学)

    题面 传送门 分析 假设k是固定的,那访问到的节点编号就是\(1+(a·k \mod n )\),其中a为正整数. 通过找规律不难发现会出现循环. 通过题目中的图片我们不难发现 只有k=1,2,3,6 ...

  7. C# 值类型与引用类型的详解

    值类型与引用类型分这几种情况: 1.内存分为堆和栈,值类型的数据存储在栈中,引用类型的数据存储在堆中. 2.int numb=10,代码中的10是值类型的数据,numb只是一个指向10的变量而已.其中 ...

  8. facenet 人脸识别(一)

    前言 已完成TensorFlow Object Detection API环境搭建,具体搭建过程请参照: 安装运行谷歌开源的TensorFlow Object Detection API视频物体识别系 ...

  9. 基于TensorFlow Object Detection API进行迁移学习训练自己的人脸检测模型(二)

    前言 已完成数据预处理工作,具体参照: 基于TensorFlow Object Detection API进行迁移学习训练自己的人脸检测模型(一) 设置配置文件 新建目录face_faster_rcn ...

  10. 【记录】elastiasearch 6.4.3 版本 SearchRequestBuilder字段排序,BoolQueryBuilder

    参考地址: 1:https://www.cnblogs.com/shoutn/p/8027960.html 2:https://www.jianshu.com/p/8402eb930ae7 3:htt ...