2017 Multi-University Training Contest - Team 4 1003 Counting Divisors

34 篇文章 0 订阅
27 篇文章 0 订阅

Counting Divisors

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


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
 

题目大意:

求给定的函数值,其中 d (i )i 

解题思路:

设有 n=pa11pa22...pakk ,其中 n 的因子个数为: (a1+1)(a2+1)...(ak+1)
首先预处理出1-10^6里面所有的素数,然后枚举这些素数,在枚举[L,R]区间中这些素数的倍数,然后根据这些倍数进行素因子分解,其实就是统计[L,R]区间中有多少个枚举的素数,然后乘以K, 在加 1 计算即可。在枚举 [L,R]区间值的时候,我们需要先把 [L,R] 区间中的数用数组保存下来,然后通过数组进行素因子分解。


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 998244353;
const LL MAXN = 1e6 + 5;

int prime[MAXN], cnt;
LL p[MAXN];
void isprime()
{
    memset(prime, 0, sizeof(prime));
    cnt = 0;
    prime[1] = 1;
    for (LL i = 2; i < MAXN; i++)
    {
        if (!prime[i])
        {
            p[cnt++] = i;
            for (LL j = i * i; j < MAXN; j += i)
            {
                prime[j] = 1;
            }
        }
    }
}
LL f[MAXN], num[MAXN];
int main()
{
    isprime();
    int T;
    scanf("%d", &T);
    while (T--)
    {
        LL L, R, K;
        scanf("%lld%lld%lld", &L, &R, &K);
        LL ans = 0;
        if (L == 1)
        {
            ans = 1, L++;
        }
        int t = R - L;
        for (int i = 0; i <= t; i++)
        {
            f[i] = i + L, num[i] = 1;
        }
        for (int i = 0; i < cnt && p[i]*p[i] <= R; i++)
        {
            LL tmp = L;
            if (L % p[i])
            {
                tmp = (L / p[i] + 1) * p[i];
            }
            for (LL j = tmp; j <= R; j += p[i])
            {
                LL cnt = 0;
                while (f[j - L] % p[i] == 0)
                {
                    cnt++;
                    f[j - L] /= p[i];
                }
                num[j - L] = num[j - L] * (cnt * K + 1) % MOD;
            }
        }
        for (int i = 0; i <= t; i++)
        {
            if (f[i] == 1)
            {
                ans = (ans + num[i]) % MOD;
            }
            else
            {
                ans = (ans + num[i] * (K + 1)) % MOD;
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值