hdu 6069 Counting Divisors(求因子的个数)
Counting Divisors
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 3170 Accepted Submission(s): 1184
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<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<cstring>
#include<bits/stdc++.h> using namespace std;
const long long mod=;
long long ans,l,r,k,len;
int T;
long long f[],num[],a[];
void pre()
{
bool flag;
len=;
f[++len]=;
for(int i=;i<=1e6;i++)
{
flag=;
for(int j=;j<=sqrt(i);j++)
if (i%j==) {flag=; break;}
if (flag) f[++len]=i;
}
return;
} int main()
{
pre(); //预处理出1~1e6之间的素数
scanf("%d",&T);
for(;T>;T--)
{
scanf("%lld%lld%lld",&l,&r,&k);
for(int i=;i<=r-l;i++) {num[i]=; a[i]=i+l;} //num【i】表示 i 这个数的因子个数
ans=;
for(int i=;i<=len;i++)
{
long long s=(l/f[i])*f[i];
if (s<l) s+=f[i];
for(long long j=s;j<=r;j+=f[i])
{
long long w=;
while(a[j-l]%f[i]==)
{
a[j-l]/=f[i];
w++;
}
num[j-l]=num[j-l]*(w*k+)%mod;
}
}
for(int i=;i<=r-l;i++)
if (a[i]>) num[i]=num[i]*(k+)%mod; //特殊判断还剩下的数字!=1的情况,也就是还有一个大素数 for(int i=;i<=r-l;i++) ans=(ans+num[i])%mod;
printf("%lld\n",ans);
}
return ;
}
hdu 6069 Counting Divisors(求因子的个数)的更多相关文章
- HDU 6069 Counting Divisors
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- HDU 6069 Counting Divisors —— 2017 Multi-University Training 4
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- HDU 6069 Counting Divisors(区间素数筛法)
题意:...就题面一句话 思路:比赛一看公式,就想到要用到约数个数定理 约数个数定理就是: 对于一个大于1正整数n可以分解质因数: 则n的正约数的个数就是 对于n^k其实就是每个因子的个数乘了一个K ...
- hdu 6069 Counting Divisors 筛法
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- 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(唯一分解定理+因子数)
http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...
- hdu 6069 Counting divisors 公式+区间筛
比赛的时候把公式扣出来了,,但是没有想到用筛法算公因子,,默默学习一下.. 题解:设n=p1^(c1)p2^{c2}...pm^{cm},n=p1^c1*p2^c2...p ...
- HDU 6069 Counting Divisors (素数+筛法)
题意:给定 l,r,k,让你求,其中 l <= r <= 1e12, r-l <= 1e6, k <= 1e7. 析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选, ...
- 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 ...
随机推荐
- hadoop执行 报错
Error: java.io.IOException: Initialization of all the collectors failed. Error in last collector was ...
- MySQL变量的使用
在mysql文档中,mysql变量可分为两大类,即系统变量和用户变量. 但根据实际应用又被细化为四种类型,即局部变量.用户变量.会话变量和全局变量. 一.局部变量 mysql局部变量,只能用在begi ...
- https学习笔记三----OpenSSL生成root CA及签发证书
在https学习笔记二,已经弄清了数字证书的概念,组成和在https连接过程中,客户端是如何验证服务器端的证书的.这一章,主要介绍下如何使用openssl库来创建key file,以及生成root C ...
- SQL获取第一天最后一天
DECLARE @dtdatetime SET @dt=GETDATE() DECLARE @number int --1.指定日期该年的第一天或最后一天 --A. 年的第一天 SELECTCONVE ...
- docker mysql 数据库乱码
创建 mysql 时,需要加上编码,不然会乱码: docker run --name mysql01 -p : -e MYSQL_ROOT_PASSWORD=pwd123 -d mysql:5.5 - ...
- Field amqpTemplate in * required a single bean, but 3 were found:
Field amqpTemplate in * required a single bean, but 3 were found: Spring Boot 启动的时候报的错 使用Spring Boot ...
- 软件工程---UML理解
1.依赖关系和关联关系 1.1依赖关系是调用关系,其又分为全局依赖.参数依赖.局部依赖 1.2关联关系是结构上的关系,按照关联的强弱又具体分为关联关系.聚合关系(整体和部分的组成关系.whole-pa ...
- Shell 实践、常用脚本进阶
1.备份单个文件 #!/bin/bash #备份单个文件 DATE=`/bin/date +%y%m%d` /bin/tar -czpf /backup/$1.$DATE.tar.gz /backup ...
- 性能测试监控工具nmon详解和分析
性能测试监控工具nmon详解和分析 1.命令安装 1.查看liunx版本版本x86_64_14i 目录:cd /nmon/logs/ 版本x86_64_14i [root@localhost u06] ...
- Mybaties 实现批量修改
通常我们在做批量更新的时候都会用in 去操作,但in的数据量一上来,就变的缓慢了 修改方案: <update id="updateShufflingSeq" paramete ...