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 ...
随机推荐
- 《图解设计模式》读书笔记2-1 Template Method模式
目录 模板方法模式 类图 思想: 模板方法模式 在父类中定义流程,在子类中实现具体的方法. 类图 代码 //抽象类 public abstract class AbstractDisplay { pu ...
- 快速测试端口的连通性(HTTP/HTTPS)
ping 仅限 80 端口,命令中无法指定端口: C:\Users\Administrator>ping kikakika.com 遗失对主机的连接. 正在 Ping kikakika.com ...
- Decision Tree Algorithm
Decision Tree算法的思路是,将原始问题不断递归地细分为子问题,直到子问题直接可获得答案为止.在模型训练的过程中,根据训练集去做树的生长(Grow the tree),生长所有可能的Bran ...
- 【python】随机数相关
http://www.cnblogs.com/yd1227/archive/2011/03/18/1988015.html 该博文写的很详细,备忘. 需要注意的是,写测试脚本的时候,不要将脚本命名成跟 ...
- 边界安全 - CDN/DMZ/网络协议
CDN 工具 - LuManager CDN DMZ 网络协议 - DNS Win7下搭建DNS服务器 - BIND 根域 顶级域(即相关国家域名管理机构的数据库,如中国的CNNIC) com n ...
- 找不到/lib/modules/../build文件夹
:解决了make: *** /lib/modules/3.2.0-4-amd64/build: 没有那个文件或目录的问题,更新一下软件列表,然后sudo apt-get install linux-h ...
- Survey Results for Rebecca Murpheys Learning JavaScript Survey
时间 2016-01-27 05:40:46 Raymond Camden's Blog 原文 http://www.raymondcamden.com/2016/01/25/survey-res ...
- Scala面向对象
面向对象编程OOP: Scala vs Java 都有这三特性 封装:把属性.方法封装到类中 Person: int id, String name, Date birthday.... 需要gett ...
- [fw]Linux下tty/pty/pts/ptmx详解
基本概念: 1> tty(终端设备的统称):tty一词源于Teletypes,或者teletypewriters,原来指的是电传打字机,是通过串行线用打印机键盘通过阅读和发送信息的东西,后来这东 ...
- 【JAVA】java编译错误:编码UTF8/GBK的不可映射字符
环境: win7 cmd窗口编译 javac xx.java时报错 错误显示:错误:编码GBK的不可映射字符 背景: 分析发现是中文字符所在行报错了 查阅相关资料发现,是因为编译器设置为了utf-8, ...