HDU 6069 Counting Divisors -质因子个数-2017多校联盟4 第3题

Counting Divisors

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


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
 





/*
题意:
计算Σd(i^k),i∈[l,r],d(x)表示x的因子的个数

题解:
1.求一个数的因子个数方法:
分解质因数,质因数的指数+1再相乘
例如42 = 2^2*3^1*7^1;则因数个数为:(2+1)*(1+1)*(1+1) = 12
而 x^k = (p1^x1 * p2^x2 * ……)^k = p1^(x1*k) * p2^(x2*k) * ……
例如 42^2 = 2^4 * 3^2 * 7^2 则因数个数为(4+1)*(2+1)*(2+1) = 45

2.这样如果枚举每个i 会超时。我们选择枚举每个质数。
分解质因数时,质数枚举到 根r 以内就够了
对于区间l到r内的数,只要能除开质数p[i]的,就分解,详见代码
*/

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 1000000+10;
const ll mod = 998244353;
ll g[maxn];///g[i]表示数i+l有多少个因子
ll f[maxn];///f[i]表示第i个数是i+l,f[i]数组用来分解质因数
ll p[maxn];
bool vis[maxn];
int main()
{
    ///处理根r以内的素数
    int total = 0;
    for(int i = 2;i<maxn;++i){
        if(!vis[i]){///非偶
            p[++total] = i;
        }
        for(int j = 1;j<=total && p[j]*i<maxn;++j){
            vis[i*p[j]] = 1;
            if(i%p[j]==0) break;
        }
    }

    int t;
    scanf("%d",&t);
    while(t--){
        ll l,r,k;
        scanf("%lld%lld%lld",&l,&r,&k);
        for(ll i = 0;i<r-l+1;++i){///映射,把l~r映射到从下标0~r-l
            f[i] = i+l;
            g[i] = 1;
        }
        for(ll i = 1;i<=total && p[i]*p[i]<=r;++i){///枚举根r以内的素数就够了
            for(ll j = l/p[i]*p[i];j<=r;j+=p[i]){///枚举属于l~r之间的p[i]的倍数
                if(j<l) continue;///l/p[i]*p[i] 可能是小于l(字母L)的数或者是l
                int cnt = 0;
                while(f[j-l]%p[i] == 0){
                    f[j-l]/=p[i];
                    cnt++;
                }
                g[j-l] = (g[j-l]*(cnt*k+1))%mod;
            }
        }
        ll ans = 0;
        for(int i = 0;i<r-l+1;++i){
            if(f[i]>1){///说明这个数没有被除完,这个数是个质因子
                g[i] = g[i]*(1*k+1) % mod;
            }
            ans = (ans+g[i])%mod;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值