HDU6069:Counting Divisors(因子数统计|区间筛)
题意
计算\(\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(因子数统计|区间筛)的更多相关文章
- hdu6069 Counting Divisors 晒区间素数
/** 题目:hdu6069 Counting Divisors 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意:求[l,r]内所有数的k次方 ...
- 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 ...
- 【区间筛】2017多校训练四 HDU6069 Counting Divisors
http://acm.hdu.edu.cn/showproblem.php?pid=6069 [题意] 给定l,r,k,求 d(n)是n的因子个数 [思路] [Accepted] #include&l ...
- 【线性筛】【质因数分解】【约数个数定理】hdu6069 Counting Divisors
d(x)表示x的约数个数,让你求(l,r<=10^12,r-l<=10^6,k<=10^7) #include<cstdio> using namespace std; ...
- 2017 Multi-University Training Contest - Team 4——HDU6069&&Counting Divisors
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6069 题目意思:首先解释一下d[n]这个函数表示n有多少个因子,百度一下可以知道这个函数是一个非完全积 ...
- [SPOJ] DIVCNT2 - Counting Divisors (square) (平方的约数个数前缀和 容斥 卡常)
题目 vjudge URL:Counting Divisors (square) Let σ0(n)\sigma_0(n)σ0(n) be the number of positive diviso ...
- HDU 6069 Counting Divisors
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- DIVCNT2&&3 - Counting Divisors
DIVCNT2 - Counting Divisors (square) DIVCNT3 - Counting Divisors (cube) 杜教筛 [学习笔记]杜教筛 (其实不算是杜教筛,类似杜教 ...
- SPOJ 20713 DIVCNT2 - Counting Divisors (square)
DIVCNT2 - Counting Divisors (square) #sub-linear #dirichlet-generating-function Let \sigma_0(n)σ0 ...
随机推荐
- [React] Create and import React components with Markdown using MDXC
In this lesson I demonstrate how to use the library MDXC to create and import React components with ...
- 微信小程序 - 提取字体图标与其优化
微信小程序,无论是字体图标还是图标,都差不多,只不过是为了以后字体图标修改方便,或者加效果方便而使用它而已! 1. 下载font-awesome http://fontawesome.dashgame ...
- linux find 命令查找 复制
find 查找 find . -mtime -2 -a -path './.git*' -prune , -path './Cache' -prune -a -exec cp {} one \; rm ...
- row and col
1.行 <Row gutter={{ md: 6, lg: 12, xl: 12 }}></Row> gutter: md: 中等屏幕 桌面显示器 (≥992px) lg: 大 ...
- BZOJ 3732 Network 最小瓶颈路
题目大意:给出一个无向边,非常多询问,问x,y两地之间的最长路最短是多少. 思路:乍一看好像是二分啊. 的确这个题二分能够做.可是时间会慢非常多,有的题直接就T掉(NOIP2013货车运输). 事实上 ...
- VirtualBox中使用双网卡实现CentOS既能上网(校园网)也能使用SSHclient
近期在虚拟机中使用linux操作系统,之前使用NAT方式上网,能够畅通无阻.可是使用SSHclient连接linux虚拟机就必须为其指定固定的IP地址.依照网上的配置方法使用桥接方式,这种方式是能够的 ...
- 使用Axis2开发WebService
一.准备 1.下载Axis2.eclipse插件 axis2-1.6.2-war.zip: http://mirror.bjtu.edu.cn/apache//axis/axis2/java/core ...
- 新手必备的SEO优化工具
- Cocos Console命令总结
1. 工程创建 使用Cocos Console创建工程非常简单,安装完cocos命令之后,只需要在需要创建工程的目标目录下打开终端或命令行工具,输入下面的命令即可: cocos new -l js P ...
- swt_table 回车可编辑Esc取消
package 宿舍管理系统; import java.util.Hashtable; import org.eclipse.swt.SWT; import org.eclipse.swt.custo ...