设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)...(kc_m+1)d(n​k​​)=(kc​1​​+1)(kc​2​​+1)...(kc​m​​+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;
}

最新文章

  1. 一篇文章让Oracle程序猿学会MySql【未完待续】
  2. 我的android学习经历35
  3. ocp 1Z0-051 141题---感觉有问题
  4. IOS8Preview-Huge for developer and Massive for everyone else
  5. PS网页设计教程XXIX——如何在PS中设计一个画廊布局
  6. IE6 IE7 IE8(Q) 负边距 (margin) 导致元素溢出 hasLayout 容器时显示异常
  7. No.008 String to Integer (atoi)
  8. 05_例子讲解:rlCollisionDemo.exe
  9. uva 10652 Board Wrapping
  10. 【Heritrix基础教程之3】Heritrix的基本架构
  11. 设计模式(十一)代理模式Proxy(结构型)
  12. 打印zigzag矩阵
  13. 从硬件竞争到软实力PK——电视媒体竞争观察
  14. Python几周学习内容小结
  15. jQuery操作iframe中js函数的方法小结
  16. [Unity基础]镜头管理类
  17. Spring AOP 切面实现操作日志
  18. 02-第一个iOS程序-开发步骤
  19. 【dsu || 线段树合并】bzoj4756: [Usaco2017 Jan]Promotion Counting
  20. Django数据库的查看、删除,创建多张表并建立表之间关系

热门文章

  1. 面试题:try,catch,finally都有return语句时执行哪个 已看1
  2. 7.ORDER BY 子句
  3. git 的使用方法
  4. Django JSON-RPC
  5. 数据库 MySQL 之 基本概念
  6. Oracle——控制事务
  7. try-catch-finally对返回值的影响
  8. LightOJ 1065 Island of Survival (概率DP?)
  9. 使用Adobe Illustrator + ArcGIS绘制地图 | Map Design Using ArcGIS + Adobe Illustrator
  10. Git教程--廖雪峰