HDU 6069 Counting Divisors 【数论】

来源:互联网 发布:淘宝客服有提成吗 编辑:程序博客网 时间:2024/06/02 06:56

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

Sample Output
10482302
 

Source
2017 Multi-University Training Contest - Team 4
 

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 510const 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;}


原创粉丝点击