Counting Divisors HDU - 6069
2024-08-26 07:41:33
设n=p_1^{c_1}p_2^{c_2}...p_m^{c_m}n=p1c1p2c2...pmcm,则d(n^k)=(kc_1+1)(kc_2+1)...(kc_m+1)d(nk)=(kc1+1)(kc2+1)...(kcm+1)。
枚举不超过\sqrt{r}√r的所有质数pp,再枚举区间[l,r][l,r]中所有pp的倍数,将其分解质因数,最后剩下的部分就是超过\sqrt{r}√r的质数,只可能是00个或11个。
时间复杂度O(\sqrt{r}+(r-l+1)\log\log(r-l+1))O(√r+(r−l+1)loglog(r−l+1))。
这道题的出题者给我膜一会,666666
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000010,P=998244353;
int Case,i,j,k,p[N/10],tot,g[N],ans;ll n,l,r,f[N];
bool v[N];
void work(ll p)
{
for(ll i=l/p*p;i<=r;i+=p)if(i>=l)
{
int o=0;
while(f[i-l]%p==0)f[i-l]/=p,o++;
g[i-l]=1LL*g[i-l]*(o*k+1)%P;
}
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
for(i=2;i<N;i++)
{
if(!v[i]) p[tot++]=i;
for(j=0;j<tot && i*p[j]<N;j++)
{
v[i*p[j]]=1;
if(i%p[j]==0) break;
}
}
scanf("%d",&Case);
while(Case--)
{
scanf("%lld%lld%d",&l,&r,&k);
n=r-l;
for(i=0;i<=n;i++) f[i]=i+l,g[i]=1;
for(i=0;i<tot;i++)
{
if(1LL*p[i]*p[i]>r)break;
work(p[i]);
}
for(ans=i=0;i<=n;i++)
{
if(f[i]>1)g[i]=1LL*g[i]*(k+1)%P;
ans=(ans+g[i])%P;
}
printf("%d\n",ans);
}
return 0;
}
最新文章
- 一篇文章让Oracle程序猿学会MySql【未完待续】
- 我的android学习经历35
- ocp 1Z0-051 141题---感觉有问题
- IOS8Preview-Huge for developer and Massive for everyone else
- PS网页设计教程XXIX——如何在PS中设计一个画廊布局
- IE6 IE7 IE8(Q) 负边距 (margin) 导致元素溢出 hasLayout 容器时显示异常
- No.008 String to Integer (atoi)
- 05_例子讲解:rlCollisionDemo.exe
- uva 10652 Board Wrapping
- 【Heritrix基础教程之3】Heritrix的基本架构
- 设计模式(十一)代理模式Proxy(结构型)
- 打印zigzag矩阵
- 从硬件竞争到软实力PK——电视媒体竞争观察
- Python几周学习内容小结
- jQuery操作iframe中js函数的方法小结
- [Unity基础]镜头管理类
- Spring AOP 切面实现操作日志
- 02-第一个iOS程序-开发步骤
- 【dsu || 线段树合并】bzoj4756: [Usaco2017 Jan]Promotion Counting
- Django数据库的查看、删除,创建多张表并建立表之间关系
热门文章
- 面试题:try,catch,finally都有return语句时执行哪个 已看1
- 7.ORDER BY 子句
- git 的使用方法
- Django JSON-RPC
- 数据库 MySQL 之 基本概念
- Oracle——控制事务
- try-catch-finally对返回值的影响
- LightOJ 1065 Island of Survival (概率DP?)
- 使用Adobe Illustrator + ArcGIS绘制地图 | Map Design Using ArcGIS + Adobe Illustrator
- Git教程--廖雪峰