hdu6069(大区间素数)

Counting Divisors

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


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


题意: 给出 l, r, k.求:(lambda d(i^k))mod998244353,其中 l <= i <= r, d(i) 为 i 的因子个数.



思路:若 x 分解成质因子乘积的形式为 x = p1^a1 * p2^a2 * ... * pn^an,那么 d(x) = (a1 + 1) * (a2 + 1) * ... * (an + 1) .显然 d(x^k) = (a1 * k + 1) * (a2 * k + 1) * ... * (an * k + 1) .


#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
typedef long long ll;
const int maxn=1000100;
const ll mod=998244353;
ll prime[maxn];     //第i个素数  
bool is_prime[maxn];    //is_prime[i]为true表示i是素数
ll sum[maxn];          //代表每个数的k次的因子个数 
ll a[maxn];
//返回n以内的素数的个数  
int sieve(int n)  
{  
    int p = 0;  
    memset(is_prime,true,sizeof(is_prime)); 
    is_prime[0] = is_prime[1] = false;  
    for (int i = 2; i <= n; i++){  
        if (is_prime[i]){  
            prime[p++] = i;  
            for (int j = 2 * i; j <= n; j += i)  
                is_prime[j] = false;  
        }  
    }  
    return p;  
}
int main()
{
	int p1=sieve(maxn-1);
	int t;
	ll l,r,k;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld%lld%lld",&l,&r,&k);
		for(int i=0;i<=r-l;i++)
		{
			sum[i]=1;
			a[i]=i+l;
		}
		for(int i=0;prime[i]*prime[i]<=r;i++)
		{
			ll x=(l/prime[i]+(l%prime[i]?1:0))*prime[i];
			for(ll p=x;p<=r;p+=prime[i])
			{
				ll tmp=0;
				while(a[p-l]%prime[i]==0)
				{
					tmp++;
					a[p-l]/=prime[i];
				}
				sum[p-l]=(sum[p-l]*(tmp*k+1)%mod)%mod;
			}
		}
		ll ans=0;
		for(int i=0;i<=r-l;i++)
		{
			//其含有的质因子中有大于1e6的质数,需要加入计算 
			if(a[i]!=1)sum[i]=(sum[i]*(k+1))%mod; 
			ans=(ans+sum[i])%mod;
		}
		printf("%lld\n",ans);
	}
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值