Counting Divisors

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)

Problem Description
In mathematics, the function d(n) denotes the number of divisors of positive integer n.

For example, d(12)=6 because 1,2,3,4,6,12 are all 12's divisors.

In this problem, given l,r and k, your task is to calculate the following thing :

(∑i=lrd(ik))mod998244353

 
Input
The first line of the input contains an integer T(1≤T≤15), denoting the number of test cases.

In each test case, there are 3 integers l,r,k(1≤l≤r≤1012,r−l≤106,1≤k≤107).

 
Output
For each test case, print a single line containing an integer, denoting the answer.
 
Sample Input
3
1 5 1
1 10 2
1 100 3
 
Sample Output
10
48
2302
 
Source

官方题解:

  唯一分解定理

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stdlib.h>
#include<time.h>
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define bug(x) cout<<"bug"<<x<<endl; const int N=1e5+,M=1e6+,inf=;
const LL INF=1e18+,mod=; const int MAXN=;
int prime[MAXN];//保存素数
bool vis[MAXN];//初始化
int Prime(int n)
{
int cnt=;
memset(vis,,sizeof(vis));
for(int i=; i<n; i++)
{
if(!vis[i])
prime[cnt++]=i;
for(int j=; j<cnt&&i*prime[j]<n; j++)
{
vis[i*prime[j]]=;
if(i%prime[j]==)
break;
}
}
return cnt;
} LL num[M],ans[M]; int main()
{
int cnt=Prime();
int T;
scanf("%d",&T);
while(T--)
{
for(int i=; i<; i++)
num[i]=,ans[i]=;
LL l,r,K;
scanf("%lld%lld%lld",&l,&r,&K);
for(int q=; q<cnt; q++)
{
int i=prime[q];
LL L=(l%i==?l:(l/i+)*i);
for(LL j=L; j<=r; j+=i)
{
LL temp=j,base=;
int x=;
while(temp%i==)
{
x++;
temp/=i;
base*=i;
}
ans[j-l+]*=(1LL*K*x+)%mod;
ans[j-l+]%=mod;
num[j-l+]*=base;
}
}
for(LL i=l; i<=r; i++)
{
if(num[i-l+]!=i)
ans[i-l+]*=K+,ans[i-l+]%=mod;
}
LL out=;
for(LL i=l;i<=r;i++)
out+=ans[i-l+],out%=mod;
printf("%lld\n",out);
}
return ;
}

hdu 6069 Counting Divisors 筛法的更多相关文章

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

  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(区间素数筛法)

    题意:...就题面一句话 思路:比赛一看公式,就想到要用到约数个数定理 约数个数定理就是: 对于一个大于1正整数n可以分解质因数: 则n的正约数的个数就是 对于n^k其实就是每个因子的个数乘了一个K ...

  5. HDU 6069 Counting Divisors (素数+筛法)

    题意:给定 l,r,k,让你求,其中 l <= r <= 1e12, r-l <= 1e6, k <= 1e7. 析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选, ...

  6. HDU 6069 Counting Divisors(唯一分解定理+因子数)

    http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...

  7. 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)

    题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...

  8. hdu 6069 Counting divisors 公式+区间筛

    比赛的时候把公式扣出来了,,但是没有想到用筛法算公因子,,默默学习一下.. 题解:设n=p1^(c1)p2^{c2}...pm^{cm},n=p​1^​c​1*​​​​p​2​^c​2​​​​...p ...

  9. HDU 6069 Counting Divisors(2017 Multi-University Training Contest - Team 4 )

    Output For each test case, print a single line containing an integer, denoting the answer.   Sample ...

随机推荐

  1. [C#基础]说说lock到底锁谁?(补充与修改)

    摘要 今天在园子里面有园友反馈关于[C#基础]说说lock到底锁谁?文章中lock(this)的问题.后来针对文章中的例子,仔细想了一下,确实不准确,才有了这篇文章的补充,已经对文章中的demo进行修 ...

  2. python-selenium,关于页面滑动的操作

    //移动到元素element对象的“顶端”与当前窗口的“顶部”对齐 ((JavascriptExecutor) driver).executeScript("arguments[0].scr ...

  3. Golang闭包案例分析与普通函数对比

    闭包案例 package main import ( "fmt" "strings" //记住一定引入strings包 ) //①编写一个函数makeSuffi ...

  4. Windows死机的话,可能的一些猫病

    一.由硬件引起的原因 [散热不良] 显示器.电源和CPU在工作中发热量非常大,因此保持良好的通风状况非常重要,如果显示器过热将会导致色彩.图象失真甚至缩短显示器寿命.工作时间太长也会导致电源或显示器散 ...

  5. zabbix配置短信告警

    zabbix版本:3.0.7 短信服务商:云片网 首先在云片网添加相应签名和模板 参照格式 签名:xxx告警 模板: [xxx告警]故障:#status# 服务器:#host# 发生:#trigger ...

  6. tp5 本地安装和调试的问题

    安装的时候用官方下载的包或者用composer指定版本号,不要用git,会安装最新的包. 本地配置域名的时候出错,要不就是500要不就是找不到文件,原因是目录路径里的反斜杆加字母t被转义了,改成正斜杠 ...

  7. 网络 --- 3 socket模块 粘包

    一 .socket 模块参数及方法 二.缓冲区 三.粘包 1.两种粘包现象 ①连续的小包可能会被优化算法给组合到一起进行发送 ②第一次如果发送的数据大小2000B接收端一次性接受大小为1024, 这就 ...

  8. mysql 的delete from 和update子查询限制

    最经做项目时发现的问题,好像在update时也有... 网上查到的资料如下: 1.使用mysql进行delete from操作时,若子查询的 FROM 字句和更新/删除对象使用同一张表,会出现错误. ...

  9. C#开发者工具网

    使用key值[123456]对[50cms]进行对称加密-在线DES对称加密/解密- 开发者工具网  http://tool.sufeinet.com/Encrypt/DesEncrypt.aspx? ...

  10. tp剩余未验证内容-4

    关于pop-up被blocked的问题 首先 这个pop-up的功能叫 popup blocker , 它是浏览器(包括ff, chrome等) 自身 所内置 的一个功能, 不是 安装的外部 插件/或 ...