Counting Divisors
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1952 Accepted Submission(s): 710
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
题意:见题面吧。。。
题解:比赛的时候简直智障,感觉暴力必定过不了我就没太敢下手,后来现场搞一发Pollard_rho算法,改了将近一个多小时,还是TLE,这么难!!!果断放弃了。(还是太菜),今天补了这道题,发现和暴力的唯一区别就是区间枚举质因数的时候不是++,而是+p,woc,为什么比赛的时候没想到,就一个字母的事情,真的是菜菜菜菜菜菜啊。。。
我当时是怎么想的,直接在区间里枚举当前质因数的倍数就好了233333.。。。
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<math.h>
#include<time.h>
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
typedef long long ll;
#define inf 2147483647
#define mod 998244353
#define maxn 1000005
#define lowbit(x) (x&-x)
#define eps 1e-10
ll a[maxn]={1,1},b[maxn],c[maxn],d[maxn];
int main(void)
{
ll T,l,r,i,j,ans,cnt=0,tmp,k,res;
for(i=2;i<=maxn;i++)
{
if(a[i])
continue;
b[++cnt]=i;
for(j=i*i;j<=maxn;j+=i)
a[j]=1;
}
scanf("%lld",&T);
while(T--)
{
ans=0;
scanf("%lld%lld%lld",&l,&r,&k);
for(i=l;i<=r;i++)
c[i-l]=i,d[i-l]=1;
for(i=1;b[i]*b[i]<=r && i<=cnt;i++)
{
tmp=l-l%b[i];
if(tmp<l)tmp+=b[i];
for(j=tmp;j<=r;j+=b[i])
{
res=0;
if(c[j-l]%b[i]==0)
{
while(c[j-l]%b[i]==0)
c[j-l]/=b[i],res++;
d[j-l]=(d[j-l]*(1+k*res))%mod;
}
}
}
for(i=l;i<=r;i++)
if(c[i-l]>1)
d[i-l]=(d[i-l]*(1+k))%mod;
for(i=l;i<=r;i++)
ans=(ans+d[i-l])%mod;
printf("%lld\n",ans);
}
return 0;
}