HDU 6069-Counting Divisors(多校训练第四场->区间质因数个数)

Counting Divisors

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


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

题意:见题面吧。。。

题解:比赛的时候简直智障,感觉暴力必定过不了我就没太敢下手,后来现场搞一发Pollard_rho算法,改了将近一个多小时,还是TLE,这么难!!!果断放弃了。(还是太菜),今天补了这道题,发现和暴力的唯一区别就是区间枚举质因数的时候不是++,而是+p,woc,为什么比赛的时候没想到,就一个字母的事情,真的是菜菜菜菜菜菜啊。。。

我当时是怎么想的,直接在区间里枚举当前质因数的倍数就好了233333.。。。

#include<map>              
#include<stack>              
#include<queue>            
#include<vector>              
#include<math.h>        
#include<time.h>      
#include<stdio.h>            
#include<iostream>          
#include<string.h>              
#include<stdlib.h>              
#include<algorithm>              
using namespace std;              
typedef long long  ll;              
#define inf 2147483647             
#define mod 998244353          
#define maxn  1000005          
#define lowbit(x) (x&-x)              
#define eps 1e-10      
ll a[maxn]={1,1},b[maxn],c[maxn],d[maxn];
int main(void)
{
	ll T,l,r,i,j,ans,cnt=0,tmp,k,res;
	for(i=2;i<=maxn;i++)
	{
		if(a[i])
			continue;
		b[++cnt]=i;
		for(j=i*i;j<=maxn;j+=i)
			a[j]=1;
	}
	scanf("%lld",&T);
	while(T--)
	{
		ans=0;
		scanf("%lld%lld%lld",&l,&r,&k);
		for(i=l;i<=r;i++)
			c[i-l]=i,d[i-l]=1;
		for(i=1;b[i]*b[i]<=r && i<=cnt;i++)
		{
			tmp=l-l%b[i];
			if(tmp<l)tmp+=b[i];
			for(j=tmp;j<=r;j+=b[i])
			{
				res=0;
				if(c[j-l]%b[i]==0)
				{
					while(c[j-l]%b[i]==0)
						c[j-l]/=b[i],res++;
					d[j-l]=(d[j-l]*(1+k*res))%mod;
				}
			}
		}
		for(i=l;i<=r;i++)
			if(c[i-l]>1)
				d[i-l]=(d[i-l]*(1+k))%mod;
		for(i=l;i<=r;i++)
			ans=(ans+d[i-l])%mod;
		printf("%lld\n",ans);
	}
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值