设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;
}

Counting Divisors HDU - 6069的更多相关文章

  1. HDU 6069 Counting Divisors

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

  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 —— 2017 Multi-University Training 4

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

  5. 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 ...

  6. hdu6069 Counting Divisors 晒区间素数

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

  7. HDU 6069

    Counting Divisors Problem Description In mathematics, the function d(n) denotes the number of diviso ...

  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. Virtual Machine Definition File 2.2

    Virtual Machine Definition File 2.2 http://archives.opennebula.org/documentation:archives:rel2.2:tem ...

  2. 打印vector内容

    <span style="font-size:14px;">#include <iostream> #include <vector> #inc ...

  3. TinyMCE4.x整合教程-Xproer.WordPaster

    版权所有 2009-2017 荆门泽优软件有限公司 保留所有权利 官方网站:http://www.ncmem.com/ 产品首页:http://www.ncmem.com/webplug/wordpa ...

  4. memcpy用法

    函数原型 void *memcpy(void*dest, const void *src, size_t n); 功能 由src指向地址为起始地址的连续n个字节的数据复制到以destin指向地址为起始 ...

  5. js Date 生成某年某月的天数

    $(function () { //构造一个日期对象: var day = new Date(2014, 2, 0); //获取天数: var daycount = day.getDate(); al ...

  6. 【单例模式】Singleton pattern

    前言:有很多时候,在一个生命周期中我们只要一个对象就可以了,比如:线程池,缓存,对话框,日志,显卡驱动等等.如果造出多个实例,就会导致许多问题产生,例如:程序的行为异常.资源使用过量,或者说不一致的结 ...

  7. repeater+aspnetpager 组合分页

    页面代码 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TF_Product. ...

  8. .net core 图片合并,图片水印,等比例缩小,SixLabors.ImageSharp

    需要引用 SixLabors.ImageSharp 和SixLabors.ImageSharp.Drawing 引用方法 NuGet包管理 添加程序包来源 https://www.myget.org/ ...

  9. indexDB的使用和异步图片blob文件保存

    //调整webkit兼容性 var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || w ...

  10. 数据存储 mongodb

    数据存储 mongodb from pymongo import MongoClient import os base_dir = os.getcwd() class MongoPipeline(ob ...