[ Luogu 3935 ] Calculating
\(\\\)
\(Description\)
若\(x\)分解质因数结果为\(x=p_1^{k_1}p_2^{k_2}\cdots p_n^{k_n}\),令\(f(x)=(k_1+1)(k_2+1)\cdots (k_n+1)\)。
求\(\sum_{i=l}^rf(i)\)对\(998244353\)取模的结果。
- \(l,r\in [1,10^{14}]\)
\(\\\)
\(Solution\)
首先要知道这里定义的 \(f\) 函数的值其实就是这个数的因数个数。
连乘的含义是容斥原理,考虑要构成的约数从每一个质因子里分别选取了多少个,所以有指数加一连乘的种类数。
然后所求就变成了区间内每个数的因子个数之和,问题可以转化为前缀相减。
然后考虑区间\([1,N]\)内所有数的因子个数之和,这个东西可以枚举这个因子是什么,即
\]
然后就是除法分块的板子了。
\(\\\)
\(Code\)
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define R register
#define gc getchar
#define N 4000010
using namespace std;
typedef long long ll;
inline ll rd(){
ll x=0; bool f=0; char c=gc();
while(!isdigit(c)){if(c=='-')f=1;c=gc();}
while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=gc();}
return f?-x:x;
}
ll n,a[N];
int res,ans[N];
int main(){
n=rd();
for(R int i=1;i<=n;++i) a[i]=rd();
for(R int i=1,r=1;i<=n;++i){
if(r<i) r=i;
while(r<n&&a[r+1]%a[i]==0) ++r;
ans[i]=r;
}
for(R int i=n,l=n;i>0;--i){
if(l>i) l=i;
while(l>1&&a[l-1]%a[i]==0) --l;
res=max(res,ans[i]-l+1);
}
printf("%d",res);
return 0;
}
[ Luogu 3935 ] Calculating的更多相关文章
- [洛谷3935]Calculating
题目链接:https://www.luogu.org/problemnew/show/P3935 首先显然有\(\sum\limits_{i=l}^rf(i)=\sum\limits_{i=1}^rf ...
- 长时间停留在calculating requirements and dependencies 解决方案
如果Eclipse花费了很长的时间calculating requirements and dependencies(计算需求和依赖性 ) 这个问题通常就是在点击安装之后显示“Calculating ...
- Luogu 魔法学院杯-第二弹(萌新的第一法blog)
虽然有点久远 还是放一下吧. 传送门:https://www.luogu.org/contest/show?tid=754 第一题 沉迷游戏,伤感情 #include <queue> ...
- 长时间停留在calculating requirements and dependencies 的解决方案
如果Eclipse花费了很长的时间calculating requirements and dependencies(计算需求和依赖性 ) 这个问题通常就是在点击安装之后显示“Calculating ...
- Calculating Stereo Pairs
Calculating Stereo Pairs Written by Paul BourkeJuly 1999 Introduction The following discusses comput ...
- luogu p1268 树的重量——构造,真正考验编程能力
题目链接:http://www.luogu.org/problem/show?pid=1268#sub -------- 这道题费了我不少心思= =其实思路和标称毫无差别,但是由于不习惯ACM风格的题 ...
- Calculating simple running totals in SQL Server
Running total for Oracle: SELECT somedate, somevalue,SUM(somevalue) OVER(ORDER BY somedate ROWS BETW ...
- [luogu P2170] 选学霸(并查集+dp)
题目传送门:https://www.luogu.org/problem/show?pid=2170 题目描述 老师想从N名学生中选M人当学霸,但有K对人实力相当,如果实力相当的人中,一部分被选上,另一 ...
- [luogu P2647] 最大收益(贪心+dp)
题目传送门:https://www.luogu.org/problem/show?pid=2647 题目描述 现在你面前有n个物品,编号分别为1,2,3,--,n.你可以在这当中任意选择任意多个物品. ...
随机推荐
- MySQL JDBC URL参数(转)
MySQL的 JDBC URL格式: jdbc:mysql://[host][,failoverhost...][:port]/[database] » [?propertyName1][=prope ...
- MongoDB小结09 - update【定位修改器】
如果要操作数组中的值,可以用值在数组中的位置当做参数来删除 db.user.update({"name":"codingwhy.com"},{"$se ...
- [Javascript] Flattening nested arrays: a little exercise in functional refactoring
In this lesson we write an imperative function to flatten nested arrays, and then use the popular ma ...
- Android Studio签名打包应用
转载请注明来源: http://blog.csdn.net/kjunchen/article/details/50812391 可直接看看以下的Android Studio中签名应用 Android要 ...
- Django打造大型企业官网(三)
四.前端首页 4.1.导航条实现 (1)templates/new/index.html <!DOCTYPE html> <html lang="en"> ...
- hdu5375 Gray code(DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5375 题目大意:给你一个二进制串,带'?'的位置能够由你来决定填'1'还是'0',补充完整之后转换成 ...
- WebSphere报错指南
看了下面的文章,泥坑会叫我标题党,没错我就是啊. 1.was日志路径 ${WebSphere根路径}/AppServer/profiles/AppSrv01/logs/,比如说我的路径就是/opt/I ...
- php(cli模式)执行文件传递参数
php -f index.php hello test 2314 shell命令执行php文件不像http那样通过GET方式传参 同样php文件获取的时候也不能用$_GET方法了 而是通过$argv[ ...
- windows console Kill PID 端口查看
开始--运行--cmd 进入命令提示符 输入netstat -ano 即可看到所有连接的PID 之后在任务管理器中找到这个PID所对应的程序如果任务管理器中没有PID这一项,可以在任务管理器中选&qu ...
- ubuntu下的root的创建进入与退出
创建: 在终端中输入:sudo passwd rootEnter new UNIX password: (在这输入你的密码)Retype new UNIX password: (确定你输入的密码)pa ...