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. (c++) int 转 string,char*,const char*和string的相互转换

    一.int 和string的相互转换 1 int 转化为 string c++ //char *itoa( int value, char *string,int radix); // 原型说明: / ...

  2. SparkSQL UDF两种注册方式:udf() 和 register()

    调用sqlContext.udf.register() 此时注册的方法 只能在sql()中可见,对DataFrame API不可见 用法:sqlContext.udf.register("m ...

  3. [py][mx]django课程页显示city和机构封面图

    city和课程机构信息展示到前台去 organization/views.py from django.views.generic.base import View from organization ...

  4. POJ:3083 Children of the Candy Corn(bfs+dfs)

    http://poj.org/problem?id=3083 Description The cornfield maze is a popular Halloween treat. Visitors ...

  5. isKindOfClass isMemeberOfClass 的区分

    isKindOfClass If you use such constructs in your code, you might think it is alright to modify an ob ...

  6. SQL Server查询中特殊字符的处理方法

    SQL Server查询中,经常会遇到一些特殊字符,比如单引号“'”等,这些字符的处理方法,是SQL Server用户都应该需要知道的. 我们都知道SQL Server查询过程中,单引号“'”是特殊字 ...

  7. Ajax—web中ajax的常用方式

    什么Web2.0的特点? 1:注重用户贡献度 2:内容聚合RSS协议(每小块都个性化,单独加载单独请求,不用全部刷新--Ajax) 3:更丰富的用户体验 Ajax的概念? "Asynchro ...

  8. Rpgmaker开发心得(1)且事件

    例:NPC让你给他桃子和梨子,然后给你西瓜. 实际就是:有桃子且有梨子时的判断,但对于大多数不会直接编写脚本的同学,最好的方式就是使用开关. 思路如下: var:变量 on:开关 if(on西瓜=on ...

  9. codeforces 461C

    这题说的是 给了一张长方形的纸 1*n 然后可以按照不同的做法去折这个纸张 他有两种操作,操作1 给了一个pi 点 然后将左边的纸往右边折,第2种操作是给了一个L 和 R 然后计算出 L和R 之间的纸 ...

  10. vue 渲染页面的时候 出现闪烁问题的解决办法

    在使用vue绑定数据的时候,渲染页面时会出现变量闪烁 <div id="h_cameraman" v-cloak> <public-nav> {{ msg ...