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 ...
随机推荐
- 如何用VSCode手动编译Ace Editor
对于习惯微软VS的用户,可能很不习惯开源社区兴起的前端开发流程.随着NodeJs的兴起,JavaScript已经成为Github上开源项目最多的语言.使用微软提供的VSCode可以很好地利用这些开源项 ...
- laravel----------如何优化laravel框架
1.关闭debug (打开.env文件,把debug设置为false.) 2.缓存路由和配置(清除:php artisan config:clear php artisan route:clear ...
- 分治法——归并排序(mergesort)
首先上代码. #include <iostream> using namespace std; int arr[11]; /*两个序列合并成一个序列.一共三个序列,所以用 3 根指针来处理 ...
- Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4
Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4 from https://repo.mave ...
- vue项目初始化时npm run dev报错webpack-dev-server解决方法
vue项目初始化时npm run dev报错webpack-dev-server解决方法 原因:这是新版webpack存在的BUG,卸载现有的新版本webpack,装老版本就好webpack-dev- ...
- Qt::WindowFlags枚举类型解析
在使用Qt设计的时候经常会看到QWidget控件的构造函数出现下面这样一句话: QWidget(QWidget *parent=0,Qt::WindowFlags f=0) QWidget *pare ...
- php 把一个数组分成几个数组
<?php /* * * 把一个数组分成几个数组 * $arr 数组 * $num 获取的数量 * */ function sliceArr($arr, $num) { //数组的个数 $lis ...
- saltstack 安装
centos 6.5 saltstack 2015.5.10 (Lithium) tips:上个版本2015.5.3或者5.5有个bug,Python调用salt的unzip模块报错: 安装 在配置了 ...
- FL Studio的模式剪辑是什么?
FL Studio里的模式剪辑功能里,有一个模式菜单.模式剪辑菜单和模式选择器面板.模式可以作为模式剪辑放置在播放列表中,模式剪辑的名称显示在剪辑的标题栏中.(注意:模式注释和事件自动化可以共享相同的 ...
- Java IO流及应用(一)
IO流 IO流概述及FileWriter类的使用 FileReader类使用 缓冲流介绍和使用 IO流相关案例 NO.one IO流概述及FileWriter类使用 1.1 IO流概述及分类 IO流用 ...