2017杭电多校第四场1003 Counting Divisors (分解质因数) hdu 6069

21 篇文章 0 订阅
8 篇文章 0 订阅

Counting Divisors

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1374    Accepted Submission(s): 495


Problem Description
In mathematics, the function  d(n)  denotes the number of divisors of positive integer  n .

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 :

(i=lrd(ik))mod998244353

 

Input
The first line of the input contains an integer  T(1T15) , denoting the number of test cases.

In each test case, there are  3  integers  l,r,k(1lr1012,rl106,1k107) .
 

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

Sample Input
  
  
3 1 5 1 1 10 2 1 100 3
 

Sample Output
  
  
10 48 2302
 

Source
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:   6079  6078  6077  6076  6075 

题意:求那个公式
解题思路: n=pc11pc22...pcmmn=p ,则 d(nk)=(kc1+1)(kc2+1)...(kcm+1) 枚举不超过 r ​​ 的所有质数 p ,再枚举区间 [l,r] 中所有 p 的倍数,将其分解质因数,最后剩下的部分就是超过 r ​​ 的质数,只可能是 0 个或 1 个。 
时间复杂度 O(r+(rl+1)loglog(rl+1))
    
    
     
     
     
     
#include<cstdio>
typedef long long ll;
const int N=1000010,P=998244353;
int Case,i,j,k,p[N/10],tot,g[N],ans;ll n,l,r,f[N];bool v[N];
inline void work(ll p){
  for(ll i=l/p*p;i<=r;i+=p)if(i>=l){
    int o=0;
    while(f[i-l]%p==0)f[i-l]/=p,o++;
    g[i-l]=1LL*g[i-l]*(o*k+1)%P;//i的因子个数 
  }
}
int main(){
	//枚举到N的所有质数 
  for(i=2;i<N;i++){
    if(!v[i])p[tot++]=i;
    for(j=0;j<tot&&i*p[j]<N;j++){
      v[i*p[j]]=1;
      if(i%p[j]==0)break;
    }
  }
  scanf("%d",&Case);
  while(Case--){
    scanf("%lld%lld%d",&l,&r,&k);
    n=r-l;
    for(i=0;i<=n;i++)f[i]=i+l,g[i]=1;
    for(i=0;i<tot;i++){
      if(1LL*p[i]*p[i]>r)break;
      work(p[i]);
    }
    for(ans=i=0;i<=n;i++){
      if(f[i]>1)g[i]=1LL*g[i]*(k+1)%P; 
      ans=(ans+g[i])%P;
    }
    printf("%d\n",ans);
  }
  return 0;
}



     
     

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值