HDU 6069 Counting Divisors —— 2017 Multi-University Training 4
Counting Divisors
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 2599 Accepted Submission(s): 959
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 :

In each test case, there are 3 integers l,r,k(1≤l≤r≤1012,r−l≤106,1≤k≤107).
#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的更多相关文章
- 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 ...
- HDU 6069 Counting Divisors
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- hdu 6069 Counting Divisors(求因子的个数)
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- hdu 6069 Counting Divisors 筛法
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- HDU 6069 Counting Divisors(唯一分解定理+因子数)
http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...
- 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)
题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...
- HDU 6069 Counting Divisors (素数+筛法)
题意:给定 l,r,k,让你求,其中 l <= r <= 1e12, r-l <= 1e6, k <= 1e7. 析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选, ...
- HDU 6069 Counting Divisors(区间素数筛法)
题意:...就题面一句话 思路:比赛一看公式,就想到要用到约数个数定理 约数个数定理就是: 对于一个大于1正整数n可以分解质因数: 则n的正约数的个数就是 对于n^k其实就是每个因子的个数乘了一个K ...
- hdu 6069 Counting divisors 公式+区间筛
比赛的时候把公式扣出来了,,但是没有想到用筛法算公因子,,默默学习一下.. 题解:设n=p1^(c1)p2^{c2}...pm^{cm},n=p1^c1*p2^c2...p ...
随机推荐
- day46----JavaScript的函数及对象小结
一:函数 01:普通函数 function f1(){ console.log("Helleo world") } f1(); //调用函数 -->Helleo world ...
- GitLab 安装,配置及维护
参考: GitLab 官方文档 docker-gitlab,通过 docker-compose 快速安装 GitLab rake,是 Rails 的工具,类似 ruby 中常用的的 make.通过 R ...
- (appium+python)UI自动化_07_app UI自动化实例【叮咚搜索加车为例】
前言 初学UI自动化的小伙伴,在配置好appium+python自动化环境后,往往不知道如何下手实现自动化.小编在初期学习的时候也有这种疑惑,在此以叮咚买菜app-搜索加车为实例,展示下appium是 ...
- 浅谈JSONObject解析JSON数据
我们在做jmeter接口测试时能会用beanshell断言,一般都会将返回值转成JSONObject对象进行处理.本文选取较为复杂json格式数据,也将适用于java接口测试. JSON数据 { &q ...
- Java单链表
一.概述 二.主方法 //创建头结点 private HeroNode head = new HeroNode(-1,null,null); //计数器,用于id的自增 private static ...
- Codeforces 1091C (数学)
题面 传送门 分析 假设k是固定的,那访问到的节点编号就是\(1+(a·k \mod n )\),其中a为正整数. 通过找规律不难发现会出现循环. 通过题目中的图片我们不难发现 只有k=1,2,3,6 ...
- C# 值类型与引用类型的详解
值类型与引用类型分这几种情况: 1.内存分为堆和栈,值类型的数据存储在栈中,引用类型的数据存储在堆中. 2.int numb=10,代码中的10是值类型的数据,numb只是一个指向10的变量而已.其中 ...
- facenet 人脸识别(一)
前言 已完成TensorFlow Object Detection API环境搭建,具体搭建过程请参照: 安装运行谷歌开源的TensorFlow Object Detection API视频物体识别系 ...
- 基于TensorFlow Object Detection API进行迁移学习训练自己的人脸检测模型(二)
前言 已完成数据预处理工作,具体参照: 基于TensorFlow Object Detection API进行迁移学习训练自己的人脸检测模型(一) 设置配置文件 新建目录face_faster_rcn ...
- 【记录】elastiasearch 6.4.3 版本 SearchRequestBuilder字段排序,BoolQueryBuilder
参考地址: 1:https://www.cnblogs.com/shoutn/p/8027960.html 2:https://www.jianshu.com/p/8402eb930ae7 3:htt ...