2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)
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
分析:
如果一个数n可以分解成n=p1m1*p2m2*···*pn^mn的话(其中p1,p1···为素数),那么这个数的因子个数就为(m1+1)*(m2+1)*···*(mn+1)。
同样的,这个数由n变为nk的话,相应的次数前面分别乘以k即可。即nk的因子个数为(k*m1+1)*(km2+1)*···*(kmn+1)。
这个问题解决掉之后,我们会发现数据范围太大,我们的数组分本没办法开到那么大,我们可以把数据由前半部分来推出后半部分。
先打个1e6范围内的素数表,然后枚举可行范围内的每个素数,在区间[ l , r ]内寻找所有的该素数的倍数,将其分解质因数。
到最后如果一个数没有变成1,那就说明这个数是大于1e6的质数。(质数只有1和它本身)那么如果按照规律计算的话,只需要乘上一个(k+1)就行了。
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const int mod=998244353;
int n;
int cnt=0;
int primes[maxn];
int vis[maxn];
void get_primes()///筛选法求出1e6之内的素数,比1e6大的素数可以通过这些素数间接的求出来
{
int m=sqrt(maxn+0.5);///开方,循环到这个就行了
for(int i=2; i<=m; i++)
{
if(!vis[i])
{
for(int j=i*i; j<=maxn; j+=i)
vis[j]=1;
}
}
for(int i=2; i<=maxn; i++)
if(!vis[i]) primes[cnt++]=i;
}
ll l, r, k;
ll sum[maxn], num[maxn];
int main()
{
get_primes();
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld%lld",&l,&r,&k);
ll ans=0;
///因为l和r的范围比较大,但是它们之间的差值不会查过1e6,可以将数组缩小一点
for(ll i=l; i<=r; i++)
{
sum[i-l]=1;///个数
num[i-l]=i;///表示的是这个数
}
for(int i=0; i<cnt && primes[i]*primes[i]<=r; i++)///所有的素数
{
///求出的是[l,r]区间中第一个能够被rimes[i]整除的数
ll tmp=ceil((long double)l/primes[i])*primes[i];
for(ll j=tmp; j<=r; j+=primes[i])///枚举所有的这个素数的倍数
{
if(num[j-l]%primes[i]==0)
{
int res=0;
while(num[j-l]%primes[i]==0)
{
res++;
num[j-l]/=primes[i];
}
sum[j-l]=(sum[j-l]*(((ll)res*k+1))%mod)%mod;
}
}
}
for(ll i=l; i<=r; i++)
{
if(num[i-l]!=1)///那些本身是素数的数
sum[i-l]=(sum[i-l]*(k+1))%mod; ///大于1e6的质数
ans=(ans+sum[i-l])%mod;
}
printf("%lld\n",ans);
}
return 0;
}
2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)的更多相关文章
- 2017ACM暑期多校联合训练 - Team 6 1003 HDU 6098 Inversion (模拟)
题目链接 Problem Description Give an array A, the index starts from 1. Now we want to know Bi=maxi∤jAj , ...
- 2017ACM暑期多校联合训练 - Team 3 1003 HDU 6058 Kanade's sum (模拟)
题目链接 Problem Description Give you an array A[1..n]of length n. Let f(l,r,k) be the k-th largest elem ...
- 2017ACM暑期多校联合训练 - Team 1 1003 HDU 6035 Colorful Tree (dfs)
题目链接 Problem Description There is a tree with n nodes, each of which has a type of color represented ...
- 2017ACM暑期多校联合训练 - Team 2 1003 HDU 6047 Maximum Sequence (线段树)
题目链接 Problem Description Steph is extremely obsessed with "sequence problems" that are usu ...
- 2017ACM暑期多校联合训练 - Team 4 1004 HDU 6070 Dirt Ratio (线段树)
题目链接 Problem Description In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the foll ...
- 2017ACM暑期多校联合训练 - Team 9 1005 HDU 6165 FFF at Valentine (dfs)
题目链接 Problem Description At Valentine's eve, Shylock and Lucar were enjoying their time as any other ...
- 2017ACM暑期多校联合训练 - Team 9 1010 HDU 6170 Two strings (dp)
题目链接 Problem Description Giving two strings and you should judge if they are matched. The first stri ...
- 2017ACM暑期多校联合训练 - Team 8 1006 HDU 6138 Fleet of the Eternal Throne (字符串处理 AC自动机)
题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion ...
- 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)
题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...
随机推荐
- sublime text 多行代码注释快捷键
多行选择后按下ctrl+/ 选择类 Ctrl+D 选中光标所占的文本,继续操作则会选中下一个相同的文本. Alt+F3 选中文本按下快捷键,即可一次性选择全部的相同文本进行同时编辑.举个栗子:快速选中 ...
- ConcurrentHashMap原理分析(1.7与1.8)-put和 get 需要执行两次Hash
ConcurrentHashMap 与HashMap和Hashtable 最大的不同在于:put和 get 两次Hash到达指定的HashEntry,第一次hash到达Segment,第二次到达Seg ...
- 网络流量统计using ADB
/proc/net/xt_qtaguid/stats 基本覆盖目前所有机型且统计流量全面 adb shell cat /proc/net/xt_qtaguid/stats | grep (uid#) ...
- ZOJ3084_S-Nim
题目的意思是这样的,给定你若干堆石子,每次你可以从任一堆取出某些固定数量的石子,每次取完后必须保证没堆石子的数量不为0,谁无法操作了就算fail. 刚刚开始看题目的时候有点也没有思路,甚至连Sg函数也 ...
- 贪心(qwq)习题题解
贪心(qwq)习题题解 SCOI 题解 [ SCOI2016 美味 ] 假设已经确定了前i位,那么答案ans一定属于一个区间. 从高位往低位贪心,每次区间查找是否存在使此位答案为1的值. 比如6位数确 ...
- [AT2148] [arc063_c] Integers on a Tree
题目链接 AtCoder:https://arc063.contest.atcoder.jp/tasks/arc063_c 洛谷:https://www.luogu.org/problemnew/sh ...
- Bootstrap 环境安装
下载 Bootstrap 可以从 http://getbootstrap.com/ 上下载 Bootstrap 的最新版本.当点击这个链接时,将看到如下所示的网页: 您会看到两个按钮: Downloa ...
- Spring Boot系列教程九:Spring boot集成Redis
一.创建项目 项目名称为 “springboot_redis”,创建过程中勾选 “Web”,“Redis”,第一次创建Maven需要下载依赖包(耐心等待) 二.实现 properties配置文件中添加 ...
- 解决:warning LNK4098: 默认库“MSVCRT”与其他库的使用冲突;找到 MSIL .netmodule 或使用 /GL 编译的模块;正在。。;LINK : warning LNK4075: 忽略“/INCREMENTAL”(由于“/LTCG”规范)
原文链接地址:https://www.cnblogs.com/qrlozte/p/4844411.html 参考资料: http://blog.csdn.net/laogaoav/article/de ...
- SCOI2014极水的题解- -
话说SCOI都考了1个月了,终于拿出决心把题解补完了,但都说了是极水的题解,大家就看着玩吧- - DAY1 T1:目标是找最长不降子序列,先就有一个比较显然的结论,就是假如我们要拔高区间[L, R], ...