HDU 6069 Counting Divisors 【数论】

8 篇文章 0 订阅

Counting Divisors

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


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:   6084  6083  6082  6081  6080 
 
   
      思路:知道约束定理后就可以很容易的处理k。

             枚举质因数,再类似筛法,累计每个数。



#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
#define ll long long
#define ms(a,b)  memset(a,b,sizeof(a))
#define maxn 510
const int M=1e6+10;
const int MM=2e3+10;
const int inf=0x3f3f3f3f;
const int mod=998244353;
const double eps=1e-10;
ll r,l,k;
ll cnt[M];
int sum;
ll ans[M];
ll a[M];
ll vis[M];

void prime()
{
    sum=0;int q=1e6+10;
    ms(vis,0);
    for(int i=2;i<=q;i++){
        if(!vis[i]){
            cnt[sum++]=i;
            for(int j=i+i;j<=q;j+=i)vis[j]=1;
        }
    }
}

int main()
{
    int t;
    prime();
    scanf("%d",&t);
    while(t--){
        scanf("%lld%lld%lld",&l,&r,&k);
        for(int i=1;i<=r-l+1;i++){
                ans[i]=1;
                a[i]=l-1+i;
        }
        for(int i=0;i<sum&&cnt[i]<=r;i++){
            ll kk=l/cnt[i];
            ll p=kk*cnt[i];
            if(p<l)p+=cnt[i];
            for(;p<=r;p+=cnt[i]){
                int xx=0;
                ll pp=p;
                int pos=p-l+1;
                while(pp%cnt[i]==0){
                    xx++;
                    pp/=cnt[i];
                    a[pos]/=cnt[i];
                }
              ll nn=ans[pos];nn*=(xx*k+1)%mod;nn%=mod;
              ans[pos]=nn;
            }
        }
        ll res=0;
        for(int i=1;i<=r-l+1;i++){
           if(a[i]!=1){
             ll nn=k+1;nn*=ans[i]%mod;nn%=mod;
              ans[i]=nn;
           }
            res+=ans[i];
            res%=mod;
        }
        printf("%lld\n",res);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值