题意

计算\(\sum_{i=l}^kd(i^k)(d_i代表i的因子数)\)

分析

比赛搞了3个小时都没搞出来,有两个思维上的trick

1.要先遍历素数,再遍历[L,R],而不是枚举每个数,然后对每个数进行质因数分解

2.比赛的时候我有想过枚举素数,但是忘记因子计算公式可以分开相乘,而不用一次性求粗来,导致我们队的崩盘,我要背锅!!!

具体的做法:枚举每个素数,并枚举[L,R]中的素数的倍数,对于每个倍数,统计因子个数,用b[i]代表第i个数的因子数,具体键代码

#include <bits/stdc++.h>
using namespace std; #define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))
const ll mod = 998244353;
const int maxn=1000000;
int prime[maxn+10];
bool p[maxn+10]; inline void get_prime()
{
F(i,2,maxn)
{
if(!p[i]) prime[++prime[0]]=i;//prime[0]存储1~maxn的质数个数
for(int j=1;j<=prime[0]&&i*prime[j]<=maxn;++j)
{
p[i*prime[j]]=1;
if(i%prime[j]==0) break;
}
}
} int t;
ll L,R,K,ans;
ll a[maxn+10],b[maxn+10];//a数组存储对于每个质数除后的数,b数组存放i的因子个数 void calc()
{
int len=R-L+1;
R(i,0,len) a[i]=i+L,b[i]=1;
for(int i=1;prime[i]*1LL*prime[i]<=R;++i)
{
ll x=prime[i],k=L/x*x,cnt;
if(k<L) k+=x;
for(;k<=R;k+=x) if(a[k-L]%x==0)
{
cnt=0;
while(a[k-L]%x==0) cnt++,a[k-L]/=x;
cnt=cnt*K+1;
b[k-L]=b[k-L]*cnt%mod;
}
}
ans=0;
//R(i,0,len) printf("%I64d%c",a[i],i==len-1?'\n':' ' );
R(i,0,len)
{
if(a[i]!=1) b[i]=b[i]*(K+1)%mod;
//printf("%I64d%c",b[i],i==len-1?'\n':' ' );
ans=(ans+b[i])%mod;
}
} int main()
{
get_prime();
for(scanf("%d",&t);t--;)
{
scanf("%lld %lld %lld",&L,&R,&K);
calc();
printf("%I64d\n",ans );
}
return 0;
}

HDU6069:Counting Divisors(因子数统计|区间筛)的更多相关文章

  1. hdu6069 Counting Divisors 晒区间素数

    /** 题目:hdu6069 Counting Divisors 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意:求[l,r]内所有数的k次方 ...

  2. 2017 Multi-University Training Contest - Team 4 hdu6069 Counting Divisors

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6069 题目: Counting Divisors Time Limit: 10000/5000 ...

  3. 【区间筛】2017多校训练四 HDU6069 Counting Divisors

    http://acm.hdu.edu.cn/showproblem.php?pid=6069 [题意] 给定l,r,k,求 d(n)是n的因子个数 [思路] [Accepted] #include&l ...

  4. 【线性筛】【质因数分解】【约数个数定理】hdu6069 Counting Divisors

    d(x)表示x的约数个数,让你求(l,r<=10^12,r-l<=10^6,k<=10^7) #include<cstdio> using namespace std; ...

  5. 2017 Multi-University Training Contest - Team 4——HDU6069&&Counting Divisors

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6069 题目意思:首先解释一下d[n]这个函数表示n有多少个因子,百度一下可以知道这个函数是一个非完全积 ...

  6. [SPOJ] DIVCNT2 - Counting Divisors (square) (平方的约数个数前缀和 容斥 卡常)

    题目 vjudge URL:Counting Divisors (square) Let σ0(n)\sigma_0(n)σ0​(n) be the number of positive diviso ...

  7. HDU 6069 Counting Divisors

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

  8. DIVCNT2&&3 - Counting Divisors

    DIVCNT2 - Counting Divisors (square) DIVCNT3 - Counting Divisors (cube) 杜教筛 [学习笔记]杜教筛 (其实不算是杜教筛,类似杜教 ...

  9. SPOJ 20713 DIVCNT2 - Counting Divisors (square)

    DIVCNT2 - Counting Divisors (square) #sub-linear #dirichlet-generating-function Let \sigma_0(n)σ​0​​ ...

随机推荐

  1. vue2.0 自定义过滤器(filter)实例

    一.过滤器简介 (1)过滤器创建 过滤器的本质 是一个有参数 有返回值的方法 new Vue({ filters:{ myCurrency:function(myInput){ return 处理后的 ...

  2. mongoVUE 破解方法

    mongoVUE1.5.3的破解方法其实很简单 注册表中查找B1159E65-821C3-21C5-CE21-34A484D54444中的子项4FF78130 ,删除其下的三个子项即可. 开始-运行- ...

  3. 整理对Spark SQL的理解

    Catalyst Catalyst是与Spark解耦的一个独立库,是一个impl-free的运行计划的生成和优化框架. 眼下与Spark Core还是耦合的.对此user邮件组里有人对此提出疑问,见m ...

  4. [leetcode] database解题记录

    175 Combine Two Tables 题目:左连接Person表和Address表. select FirstName,LastName,City,State from Person p le ...

  5. FPGA 功耗结构设计

    1 相对于ASIC.FPGA是耗电器件,不适合超低功耗设计技术. 2 在CMOS技术中电路的动态功耗与门和金属引线的充放电有关,电容消耗电流的一般方程为 I=V* C*f V 是电压.对于FPGA来说 ...

  6. ribbon负载均衡进行服务消费

    相同服务以不同端口形式注册到eureka上,ribbon从eureka上获取冰进行服务消费,会偶现如下现象: I/O error on GET request for "http://COM ...

  7. 翻译:A Tutorial on the Device Tree (Zynq) -- Part IV

    获取资源信息 内核模块驱动加载之后,就开始把硬件资源管理起来,如读写寄存器.接收中断. 来看看设备树里的一条: xillybus_0: xillybus@50000000 { compatible = ...

  8. queue_action

    http://www.learn4master.com/programming-language/python/python-queue-for-multithreading

  9. ZeroMQ 初步认识

    http://www.danieleteti.it/zeromq-for-delphi/ https://my.oschina.net/zeroflamy/blog/109457 http://zer ...

  10. 单字节的FIFO缓存(30天自制操作系统--读书笔记)

    从今天起,写一些读书笔记.最近几个月都在看<30天自制操作系统这本书>,书虽说看的是电子书,但可以花钱买的正版书,既然花费了金钱,就总得有些收获. 任何人都不能总是固步自封,想要进步就得学 ...