hdu 6069 Counting Divisors(区间筛)
2017-08-04 10:38
381 查看
Counting DivisorsTime 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 |
#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 DivisorsTime 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 |
相关文章推荐
- HDU 6069 数论 区间素数筛(+赛后反思
- HDU 6069 Counting Divisors【区间素筛】【经典题】【好题】
- hdu 6069 统计区间约数的个数 2017 Multi-University Training Contest - Team 4
- hdu 6069 区间筛
- Hdu 6069 Counting Divisors【素数区间筛+预处理素因子分解】
- HDU 6069 Counting Divisors(枚举区间)(素数筛模版)
- HDU 6069 求区间[L,R]每个数的k次方的因子数之和
- Hdu 6069 - Counting Divisors(区间筛质因子)
- HDU 6069 Counting Divisors(区间素数筛法)
- (2017多校训练第四场)HDU - 6069 Counting Divisors 区间筛
- hdu 6069 区间筛
- [hdu 6069]素数筛+区间质因数分解
- HDU 6069 数学题,区间素数筛
- HDU-6069 Counting Divisors - 2017 Multi-University Training Contest - Team 4(分解质因子区间筛法)
- hdu 6069 Counting divisors 公式+区间筛
- HDU 4348 To the moon(主席树区间更新)
- HDU 5893 List wants to travel(树链剖分+区间合并)
- hdu 4902 Nice boat 多校第四场 线段树的区间置数+区间更新
- hdu 5900 QSC and Master 区间dp
- hdu 4027 Can you answer these queries? 求区间N次根的和 线段树