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

来源:互联网 发布:ubuntu 命令不提示 编辑:程序博客网 时间:2024/06/08 08:09

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
31 5 11 10 21 100 3
 

Sample Output
10482302
 

Source
2017 Multi-University Training Contest - Team 4
 





/*题意:计算Σ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) = 452.这样如果枚举每个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;}

原创粉丝点击