[洛谷3935]Calculating
题目链接:https://www.luogu.org/problemnew/show/P3935
首先显然有\(\sum\limits_{i=l}^rf(i)=\sum\limits_{i=1}^rf(i)-\sum\limits_{i=1}^{l-1}f(i)\),于是问题转化为了如何求\(\sum\limits_{i=1}^nf(i)\),即\(\sum\limits_{i=1}^n\sum\limits_{d|i}1\),调整枚举顺序有\(\sum\limits_{d=1}^n\sum\limits_{i=1}^{\lfloor\frac{n}{d}\rfloor}1\),即\(\sum\limits_{d=1}^n\lfloor\dfrac{n}{d}\rfloor\),由于\(n\)很大,所以我们使用整除分块即可
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
static char buf[1000000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
int x=0,f=1; char ch=gc();
for (;ch<'0'||ch>'9';ch=gc()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=gc()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline int read(){
int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline void print(int x){
if (x<0) putchar('-'),x=-x;
if (x>9) print(x/10);
putchar(x%10+'0');
}
const int p=998244353;
int solve(ll n){
int res=0;
for (ll i=1,pos;i<=n;i=pos+1){
pos=n/(n/i); int len=(pos-i+1)%p;
res=(res+1ll*len*(n/i)%p)%p;
}
return res;
}
int main(){
ll l,r;
scanf("%lld%lld",&l,&r);
printf("%d\n",(solve(r)-solve(l-1)+p)%p);
return 0;
}
[洛谷3935]Calculating的更多相关文章
- 洛谷P3935 Calculating(整除分块)
题目链接:洛谷 题目大意:定义 $f(x)=\prod^n_{i=1}(k_i+1)$,其中 $x$ 分解质因数结果为 $x=\prod^n_{i=1}{p_i}^{k_i}$.求 $\sum^r_{ ...
- 洛谷P3935 Calculating (莫比乌斯反演)
P3935 Calculating 题目描述 若xx分解质因数结果为\(x=p_1^{k_1}p_2^{k_2}\cdots p_n^{k_n},令f(x)=(k_1+1)(k_2+1)\cdots ...
- [洛谷P3935]Calculating
题目大意:设把$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)$,求$\su ...
- 洛谷 - P3935 - Calculating - 整除分块
https://www.luogu.org/fe/problem/P3935 求: \(F(n)=\sum\limits_{i=1}^{n}d(i)\) 枚举因子\(d\),每个因子\(d\)都给其倍 ...
- 洛谷 P3935 Calculating
虽然对这道题没有什么帮助,但是还是记一下:约数个数也是可以线性筛的 http://www.cnblogs.com/xzz_233/p/8365414.html 测正确性题目:https://www.l ...
- 洛谷 P3935 Calculating 题解
原题链接 一看我感觉是个什么很难的式子-- 结果读完了才发现本质太简单. 算法一 完全按照那个题目所说的,真的把质因数分解的结果保留. 最后乘. 时间复杂度:\(O(r \sqrt{r})\). 实际 ...
- 整除分块学习笔记+[CQOI2007]余数求和(洛谷P2261,BZOJ1257)
上模板题例题: [CQOI2007]余数求和 洛谷 BZOJ 题目大意:求 $\sum^n_{i=1}k\ mod\ i$ 的值. 等等……这题就学了三天C++的都会吧? $1\leq n,k\leq ...
- 洛谷1640 bzoj1854游戏 匈牙利就是又短又快
bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...
- 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.
没有上司的舞会 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...
随机推荐
- 【转】hibernate懒加载的问题,failed to lazily initialize a collection of role
hibernate懒加载的问题,failed to lazily initialize a collection of role hibernate懒加载的问题,failed to lazily in ...
- # <center>merge表不可用的问题</center>
最近碰到了个很有意思的问题,值得一写 给merge表和基础表添加索引时发生了一个问题,不管是先给merge表加索引还是基础表加索引,如果表数据量大都会导致加索引期间对merge表的查询不可用,因为使用 ...
- HTML5 实现文件拖放上传
1. [图片] 5375acf5gw1dusqsscfksj.jpg 2. [代码][HTML]代码 <!DOCTYPE html><html lang="en" ...
- Asterisk 拨号方案中截取字符串
在dialplan中要截取字符串可用如下几种方式: 1.转到agi中由php进行处理,这种方法比较简单,在这里不再缀述 2.在dialplan中利用内置的方法进行截取 如 [test] exten = ...
- oracle 导入imp 命令
最常用的 imp name/password@IP:1521/orcl[库] file="c:\123.dmp" full=y ignore=y. 例:imp abc/ ...
- 「LuoguP1379」 八数码难题(迭代加深
[P1379]八数码难题 - 洛谷 题目描述 在3×3的棋盘上,摆有八个棋子,每个棋子上标有1至8的某一数字.棋盘中留有一个空格,空格用0来表示.空格周围的棋子可以移到空格中.要求解的问题是:给出一种 ...
- P2647 最大收益
题目描述 现在你面前有n个物品,编号分别为1,2,3,……,n.你可以在这当中任意选择任意多个物品.其中第i个物品有两个属性Wi和Ri,当你选择了第i个物品后,你就可以获得Wi的收益:但是,你选择该物 ...
- cordova 使用H5混合开发APP
cordova 中文官网 http://cordova.axuer.com/docs/zh-cn/latest/
- JS自动让手机调出软键盘,进行输入
$('.search').click(function(){ $('input[type=text]').focus(); //让input框自动聚焦就可以让手机自动调出软键盘 });
- 2.SJ-SLAM-14
第三讲 三维空间刚体运动 本讲目标 理解三维空间的刚体运动描述方式:旋转矩阵.变换矩阵.四元数和欧拉角. 掌握Eigen库的矩阵.几何模块使用方法. 3.1 点.向量和坐标系,旋转矩阵 二维空间与三维 ...