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 :
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(1≤T≤15)
, denoting the number of test cases.
In each test case, there are 3 integers l,r,k(1≤l≤r≤1012,r−l≤106,1≤k≤107) .
In each test case, there are 3 integers l,r,k(1≤l≤r≤1012,r−l≤106,1≤k≤107) .
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
思路:知道约束定理后就可以很容易的处理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;
}