您的位置:首页 > 其它

hdu 6069 Counting Divisors(区间筛)

2017-08-04 10:38 381 查看

Counting Divisors

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)

Total Submission(s): 1504    Accepted Submission(s): 555


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(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).
 

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

 
一个数有多少个因数等于,这个数 所有素数(幂的数量+1)相乘

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
typedef long long LL;
const LL mod = 998244353;
const LL maxn = 1e6;
int prime
, vis
, cnt=0;
LL ans
, pro
;
void init()
{
memset(vis,0,sizeof(vis));
for(int i=2; i<=maxn; i++)
{
if(!vis[i]) prime[cnt++]=i;
for(int j=2*i; j<=maxn; j+=i) vis[j]=1;
}
return ;
}

int main()
{
init();
int t, n;
scanf("%d", &t);
while(t--)
{
LL a, b, k;
scanf("%lld %lld %lld",&a, &b, &k);
for(int i=1; i<=b-a+1; i++) ans[i]=1,pro[i]=1;
for(int num=0; num<cnt; num++)
{
LL x=max(1LL,(a+prime[num]-1)/prime[num]*prime[num]), c=0;
if(x>b) break;
for(LL i=x; i<=b; i+=prime[num])
{
LL tmp=i, c=0;
while(tmp%prime[num]==0)
{
c++;
pro[i-a+1]=pro[i-a+1]*prime[num];
tmp/=prime[num];
}
ans[i-a+1]=ans[i-a+1]*(k*c+1)%mod;
}
}
for(LL i=1; i<=b-a+1; i++)
if(pro[i]!=(a+i-1)) ans[i]=ans[i]*(k+1)%mod;
LL sum=0;
for(LL i=1;i<=b-a+1;i++) sum=(sum+ans[i])%mod;
printf("%lld\n",sum);
}
return 0;
}


Counting Divisors

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)

Total Submission(s): 1504    Accepted Submission(s): 555


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(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).
 

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

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: