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
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) = 45

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

#include 
#include 
#include 
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;i1){///说明这个数没有被除完,这个数是个质因子
                g[i] = g[i]*(1*k+1) % mod;
            }
            ans = (ans+g[i])%mod;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

你可能感兴趣的:(高精度,枚举)