http://acm.hdu.edu.cn/showproblem.php?pid=6069

题意:

思路:

根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{m}}^{pm}$,那么n的因子数就是

n的k次方也是一样的,也就是p前面乘个k就可以了。

先打个1e6范围的素数表,然后枚举每个素数,在[ l , r ]寻找该素数的倍数,将其分解质因数。

到最后如果一个数没有变成1,那就说明这个数是大于1e6的质数。(它就只有0和1两种选择)

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn=1e6+;
const int mod=; int n;
int cnt=;
int primes[maxn];
int vis[maxn]; void get_primes()
{
int m=sqrt(maxn+0.5);
for(int i=;i<=m;i++)
{
if(!vis[i])
{
for(int j=i*i;j<=maxn;j+=i)
vis[j]=;
}
}
for(int i=;i<=maxn;i++)
if(!vis[i]) primes[cnt++]=i;
} ll l, r, k;
ll sum[maxn], num[maxn]; int main()
{
//freopen("in.txt","r",stdin);
get_primes();
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld%lld",&l,&r,&k); ll ans=;
for(ll i=l;i<=r;i++) {sum[i-l]=;num[i-l]=i;} for(int i=; i<cnt && primes[i]*primes[i]<=r; i++)
{
ll tmp=ceil((long double)l/primes[i])*primes[i];
for(ll j=tmp;j<=r;j+=primes[i])
{
if(num[j-l]%primes[i]==)
{
int res=;
while(num[j-l]%primes[i]==)
{
res++;
num[j-l]/=primes[i];
}
sum[j-l]=(sum[j-l]*(((ll)res*k+))%mod)%mod;
}
}
} for(ll i=l;i<=r;i++)
{
if(num[i-l]!=) sum[i-l]=(sum[i-l]*(k+))%mod; //大于1e6的质数
ans=(ans+sum[i-l])%mod;
}
printf("%lld\n",ans);
}
return ;
}

HDU 6069 Counting Divisors(唯一分解定理+因子数)的更多相关文章

  1. hdu 6069 Counting Divisors 筛法

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  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 公式+区间筛

    比赛的时候把公式扣出来了,,但是没有想到用筛法算公因子,,默默学习一下.. 题解:设n=p1^(c1)p2^{c2}...pm^{cm},n=p​1^​c​1*​​​​p​2​^c​2​​​​...p ...

  5. 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 ...

  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(2017 Multi-University Training Contest - Team 4 )

    Output For each test case, print a single line containing an integer, denoting the answer.   Sample ...

随机推荐

  1. 010-jdk1.8版本新特性二-Optional类,Stream流

    1.5.Optional类 1.定义 Optional 类是一个可以为null的容器对象.如果值存在则isPresent()方法会返回true,调用get()方法会返回该对象. Optional 是个 ...

  2. windows安装并破解navicat.

    1:下载以下两个文件. patchNavicat.exe:  https://pan.baidu.com/s/1ZtV20GUGfZHcXHRTEb5tYg navicatforMysql.exe:  ...

  3. df值自由度学习[转载]

    转自:https://www.applysquare.com/topic-cn/78TAnIzZ6/ https://zhidao.baidu.com/question/175605082855699 ...

  4. PAT 1030 Travel Plan[图论][难]

    1030 Travel Plan (30)(30 分) A traveler's map gives the distances between cities along the highways, ...

  5. mysql 常用命令 常用SQL语句

    维护命令 数据库 ##创建数据库 mysql> create database test; Query OK, 1 row affected ##删除数据库 mysql> drop dat ...

  6. keras之save & reload model

    import numpy as np np.random.seed(1337) # for reproducibility from keras.models import Sequential fr ...

  7. Air Jordan 1 Los Primeros Will be unveiled

    This new pair of Air Jordan 1 Los Primeros is part of the popular Air-Jordan- Line signature and is ...

  8. 通过脚本获取form表单的数值而不是submit

    jQuery的serialize()方法通过序列化表单值,创建URL编码文本字符串,我们就可以选择一个或多个表单元素,也可以直接选择form将其序列化,如: <form action=" ...

  9. VS中代码对齐等快捷键

    在VS2008中,选定代码后,按Ctrl+K+F组合键,可以自动进行代码对齐. 注意:要先按下Ctrl和K,再按下F,因为Ctrl+F是查找的快捷键. 也可以先按下Ctrl+K,再按下Ctrl+F. ...

  10. Lower Power with CPF(四)

    CPF从Front-end到Back-end(RTL--GDSII)的整个流程: 1)Creating a CPF file:来在前端就建立lower power的规范. 2)检查CPF文件的正确性, ...