题目链接: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的更多相关文章

  1. 洛谷P3935 Calculating(整除分块)

    题目链接:洛谷 题目大意:定义 $f(x)=\prod^n_{i=1}(k_i+1)$,其中 $x$ 分解质因数结果为 $x=\prod^n_{i=1}{p_i}^{k_i}$.求 $\sum^r_{ ...

  2. 洛谷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 ...

  3. [洛谷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 ...

  4. 洛谷 - P3935 - Calculating - 整除分块

    https://www.luogu.org/fe/problem/P3935 求: \(F(n)=\sum\limits_{i=1}^{n}d(i)\) 枚举因子\(d\),每个因子\(d\)都给其倍 ...

  5. 洛谷 P3935 Calculating

    虽然对这道题没有什么帮助,但是还是记一下:约数个数也是可以线性筛的 http://www.cnblogs.com/xzz_233/p/8365414.html 测正确性题目:https://www.l ...

  6. 洛谷 P3935 Calculating 题解

    原题链接 一看我感觉是个什么很难的式子-- 结果读完了才发现本质太简单. 算法一 完全按照那个题目所说的,真的把质因数分解的结果保留. 最后乘. 时间复杂度:\(O(r \sqrt{r})\). 实际 ...

  7. 整除分块学习笔记+[CQOI2007]余数求和(洛谷P2261,BZOJ1257)

    上模板题例题: [CQOI2007]余数求和 洛谷 BZOJ 题目大意:求 $\sum^n_{i=1}k\ mod\ i$ 的值. 等等……这题就学了三天C++的都会吧? $1\leq n,k\leq ...

  8. 洛谷1640 bzoj1854游戏 匈牙利就是又短又快

    bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...

  9. 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.

    没有上司的舞会  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond       题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...

随机推荐

  1. Bestcoder BestCoder Round #28 A Missing number(查找缺失的合法数字)

    Problem Description There is a permutation without two numbers in it, and now you know what numbers ...

  2. 配置Nginx四层负载均衡

    nginx 支持TCP转发和负载均衡的支持 实现下面的架构: 看配置: #user nobody; worker_processes 1; #error_log logs/error.log; #er ...

  3. linux应用之mysql数据库指定版本的yum安装(centos)

    A Quick Guide to Using the MySQL Yum Repository Abstract The MySQL Yum repository provides RPM packa ...

  4. touch实现滑动删除

    请用chrome手机模式查看或者在手机上查看(转载请注明出处) <!DOCTYPE html> <html> <head> <meta charset=&qu ...

  5. UVA-11374(最短路)

    题意: 机场快线有经济线和商业线,现在分别给出经济线和商业线的的路线,现在只能坐一站商业线,其他坐经济线,问从起点到终点的最短用时是多少,还有路线是怎样的; 思路: 预处理出起点到所有站的最短距离和终 ...

  6. Piggy-Bank(复习完全背包)

    传送门 题目大意: 有一个存钱的储存罐,给你它存满钱之前和之后的重量,和几类硬币的面值和重量. 求装满储钱罐时最小能得到多少钱. 题解:完全背包变形. 因为要求最小 一开始赋值大数. code: #i ...

  7. bzoj 4668 冷战——并查集结构

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4668 不路径压缩,维护并查集的树的结构,查询链上最大值.按秩合并就可以暴爬. #includ ...

  8. ABI(Application Binary Interface)

    拷贝自维基百科,参考百度百科 ==>调用栈结构与系统相关. 在计算机中,应用二进制接口(英语:application binary interface,缩写为 ABI)描述了应用程序(或者其他类 ...

  9. live555 基本类之间的关系

    live555 中存在这5个最基本的类.每个类中都拥有一个BasicUsageEnvironment. 这是这几个类之间的相互关系.   MediaSession可以拥有多个subsession.

  10. K个联通块

    题意: 有一张无重边的无向图, 求有多少个边集,使得删掉边集里的边后,图里恰好有K个联通块. 解法: 考虑dp,$h(i,S)$表示有$i$个联通块,点集为$S$的图的个数,$g(S)$表示点集为S的 ...