2017 多校系列 4

Counting Divisors

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


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
 

Recommend

liuyiding   |   We have carefully selected several similar problems for you:  6132 6131 6130 6129 6128 


题意:就是求区间[l,r]的因子和。

题解:D(i)分解为不同的质因子,然后这些质因子的次方加一相乘,就是i这个数的D(i),例如12=2^2*3^1,所以D(12)=(2+1)*(1+1)=6。所以需要先将所有的素数筛出来,然后从第一个素数开始遍历一遍记录每一个素数对于某个数的贡献。(讲的不清楚看代码吧……)



ac code:

#include <sstream>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std;

#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define sd1(a) scanf("%lf",&a)
#define sd2(a,b) scanf("%lf%lf",&a,&b)
#define ss1(s)  scanf("%s",s)
#define pi1(a)    printf("%d\n",a)
#define pi2(a,b)  printf("%d %d\n",a,b)
#define mset(a,b)   memset(a,b,sizeof(a))
#define forb(i,a,b)   for(int i=a;i<b;i++)
#define ford(i,a,b)   for(int i=a;i<=b;i++)

typedef long long LL;
const int N=1e7+5;
const int M=6666666;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-7;
const int mod=998244353;
const long long MAXP = 1000006;
long long prime[MAXP] = {0},num_prime = 0;
LL isNotPrime[MAXP] = {1, 1};
LL a[MAXP],sum[MAXP];


int main()
{
    for(long long i = 2 ; i <  MAXP ; i ++)//模板素数筛法
    {
        if(! isNotPrime[i])
            prime[num_prime ++]=i;
        for(long long j = 0 ; j < num_prime && i * prime[j] <  MAXP ; j ++)
        {
            isNotPrime[i * prime[j]] = 1;
            if( !(i % prime[j]))
                break;
        }
    }
    int T;
    si1(T);
    while(T--)
    {
        LL l,r;
        int k;
        scanf("%lld%lld",&l,&r);
        si1(k);
        for(LL i=0;i<=r-l;i++)
        {
            sum[i]=1;//记录每一个数的质因子的乘积,所以初始为1
            a[i]=l+i;//记录每一个数
        }
        for(LL i=0;i<num_prime;i++)
        {
            LL st=(l/prime[i]+(l%prime[i]?1:0))*prime[i];//找到距离l最近的第i个素数
            for(LL j=st;j<=r;j+=prime[i])//将所有该素数的合数找出来
            {
                LL cnt=0;
                while(a[j-l]%prime[i]==0)
                {
                    cnt++;//记录该素数的贡献度
                    a[j-l]/=prime[i];
                }
                sum[j-l]=(sum[j-l]*((cnt*k+1)%mod))%mod;//记录该数的质因子的乘积
            }
        }
        LL ans=0;
        for(LL i=0;i<=r-l;i++)
        {
            if(a[i]!=1) sum[i]=(sum[i]*((k+1)%mod))%mod;//可能a[i]是一个大于1e6的大素数(或大合数),但只有一个没有记录贡献的素数
            ans=(ans+sum[i])%mod;//求和,记得取模
        }
        printf("%lld\n",ans);
    }
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值