Counting Divisors

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
 
这题实质上就是分解质因数,不过不能对每个数都分解一次,这样肯定超时。
要用线性的方法求质因数。
设i可以分解为a1,a2,a3,a4……am,则总数加上(a1*k+1)*(a2*k+1)*……(am*k+1)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#define ll long long
using namespace std;
#define ll long long
const int mod=;
const int maxn=;
int prime[maxn];
bool vis[maxn];
int top;
ll a[maxn];
ll b[maxn]; void pri()
{
top=;
memset(vis,,sizeof vis);
vis[]=;
for(int i=; i<maxn; i++)
{
if(!vis[i])
prime[top++]=i;
for(int j=; j<top&&i*prime[j]<maxn; j++)
{
vis[i*prime[j]]=;
if(i%prime[j]==)
break;
}
}
} void fun(ll l,ll r,ll k)
{
for(ll i=l; i<=r; i++)
b[i-l]=i;
for(ll i=l; i<=r; i++)
a[i-l]=;
for(ll i=; i<top&&prime[i]<=sqrt(r); i++)
{
ll x=l/prime[i];
if(x*prime[i]<l)
x++;
for(ll j=x; j*prime[i]<=r; j++)
{
ll s=;
while(b[prime[i]*j-l]%prime[i]==)
{
s++;
b[prime[i]*j-l]/=prime[i];
}
a[prime[i]*j-l]=a[prime[i]*j-l]*(s*k+)%mod;
}
}
for(ll i=l; i<=r; i++)
if(b[i-l]>)
a[i-l]=a[i-l]*(k+)%mod;
} int main()
{
pri();
int T;
scanf("%d",&T);
while(T--)
{
ll l,r;
ll k;
scanf("%lld%lld%lld",&l,&r,&k);
ll sum=;
fun(l,r,k);
for(ll i=l; i<=r; i++)
sum=(sum+a[i-l])%mod;
printf("%lld\n",sum);
}
return ;
}

HDU 6069的更多相关文章

  1. HDU 6069 Counting Divisors(唯一分解定理+因子数)

    http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...

  2. HDU 6069 Counting Divisors

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  3. hdu 6069 Counting Divisors(求因子的个数)

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  4. hdu 6069 Counting Divisors 筛法

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  5. 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)

    题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...

  6. HDU 6069 Counting Divisors (素数+筛法)

    题意:给定 l,r,k,让你求,其中 l <= r <= 1e12, r-l <= 1e6, k <= 1e7. 析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选, ...

  7. Counting Divisors HDU - 6069

    设n=p_1^{c_1}p_2^{c_2}...p_m^{c_m}n=p​1​c​1​​​​p​2​c​2​​​​...p​m​c​m​​​​,则d(n^k)=(kc_1+1)(kc_2+1)...( ...

  8. [hdu 6069]素数筛+区间质因数分解

    给[L,R]区间的每一个数都质因数分解的复杂度可以达到(R-L)logR,真的涨姿势…… 另外,质因数分解有很重要的一点,就是只需要打sqrt(R)以内的素数表就够了……因为超过sqrt(R)的至多只 ...

  9. HDU 6069 Counting Divisors(区间素数筛法)

    题意:...就题面一句话 思路:比赛一看公式,就想到要用到约数个数定理 约数个数定理就是: 对于一个大于1正整数n可以分解质因数: 则n的正约数的个数就是 对于n^k其实就是每个因子的个数乘了一个K ...

随机推荐

  1. w3c编程挑战-初级脚本算法

    之前偶然看到了w3c上的编程挑战题,就像拿来试试手,先做的是初级脚本算法,总体不难,如果有更好的方法,希望能一起交流! 1.翻转字符串 先把字符串转化成数组,再借助数组的reverse方法翻转数组顺序 ...

  2. [HNOI2009]梦幻布丁 算法技巧之邻接链

    题目描述 N个布丁摆成一行,进行M次操作.每次将某个颜色的布丁全部变成另一种颜色的,然后再询问当前一共有多少段颜色.例如颜色分别为1,2,2,1的四个布丁一共有3段颜色. 输入输出格式 输入格式: 第 ...

  3. golang 私钥"加密"公钥"解密"

    ---恢复内容开始---   之前工作主要使用C/C++与银行/第三方支付对接,但C/C++无法满足客户"当天给协议明天实盘上载"的开发速度以及现公司一些特殊情况,所以决定用go来 ...

  4. test_markdown

    add modifications 非科学计数法显示数字 citation[^ref1] format bank% do not use scientific expression format lo ...

  5. vue1与vue2的路由 以及vue2项目大概了解

    vue1的路由 1.设置根组件  Vue.extend() 2.设置局部组件  Vue.extend({template:"/home"}) 3.实例化路由   var route ...

  6. [leetcode-604-Design Compressed String Iterator]

    Design and implement a data structure for a compressed string iterator. It should support the follow ...

  7. [leetcode-530-Minimum Absolute Difference in BST]

    Given a binary search tree with non-negative values, find the minimum absolute difference between va ...

  8. css 背景图片自适应

    body{ height:100%; overflow:hidden;} .bg { background-image: url(../../img/beijing.jpg); width:100%; ...

  9. 理解oauth2.0【转载】

    原文出处: http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html OAuth是一个关于授权(authorization)的开放网络标准,在全世界得 ...

  10. ASP搜索查询

    html code: <form name="frm_Search" method="get" action="Search.asp" ...