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. Windows定时关机

    用shutdown命令.开始菜单>运行,输入shutdown -s -t 7200 (两个小时之后关机)at 12:00 shutdown -s (12:00关机) 其他设置:shutdown ...

  2. Javascript实现Base64解码

    工作中需要用到,在stackoverflow中找到的,实践证明可用. function decode_base64(s) { var e = {}, i, k, v = [], r = '', w = ...

  3. C++11 单例类实现

    单例类: (1) 单例类保证全局只有一个唯一的实例对象. (2) 单例类保证只有唯一的接口获取这唯一实例. 非线程安全的单例类举例: class CSingleton { public: ~CSing ...

  4. 如何给两个swiper建立关系

    单个swiper已经满足不了需求了. 各种花式轮播已经慢慢进入市场.swiper该如何立足,那么请看. <div class="swiper-container"> & ...

  5. 一些java方面面试题,没事做做看看(带答案)

    1. Switch能否用string做参数? a.在?Java? <http://lib.csdn.net/base/java>7 之前, switch 只能支持byte,short,ch ...

  6. jquery一次绑定多个元素事件

    jquery一次绑定多个元素事件 $(".peoplenum,input[name$='otherAmount'],#aa,#bb").bind("change" ...

  7. php倒计时防刷新

    <?php //php的时间是以秒算.js的时间以毫秒算 date_default_timezone_set("Asia/Hong_Kong");//地区 //配置每天的活动 ...

  8. iOS 实现简单的毛玻璃效果

    最近在整理导航栏的渐隐渐现效果,整理过程中偶然学会了图片的毛玻璃效果实现,很简单,不多说了,先上图看看效果对比, 这是原图, 这是加了效果后的,创建图片的代码就不上了,下面看下添加效果的代码: // ...

  9. 使用UDP完成网络通信

    语言聊天有可以接受丢包但是不能接受乱序的特性,所以可以采用UDP来 传输数据提高效率. 因为UDP本身不可靠传输的特性,为了保证玩家可靠的接入服务器和一些 操作的正确执行,还是需要一些额外的代码保证U ...

  10. 【Android Developers Training】 15. 启动一个Activity

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...