题目链接: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. javascrip中ajax

    移动端对加载速度要求比较高,由于jquery插件有270多k,无形中增加加载的速度,下面整理一下原生js中ajax: 先了解ajax的基础知识 (1)XMLHttpRequest 对象 XMLHttp ...

  2. 数据结构之 图论---最小生成树(prim + kruskal)

    图结构练习——最小生成树 Time Limit: 1000MS Memory limit: 65536K 题目描述  有n个城市,其中有些城市之间可以修建公路,修建不同的公路费用是不同的.现在我们想知 ...

  3. Js中获取显示器、浏览器以及窗口等的宽度与高度的方法

    网页可见区域宽:document.body.clientWidth 网页可见区域高:document.body.clientHeight 网页可见区域宽:document.body.offsetWid ...

  4. HTML预览 正则替换

    1. [代码][PHP]代码  <?php    if(!defined('BASEPATH')) exit('No direct script access allowed');    /** ...

  5. linux应用之nginx的安装及配置(centos)

    Ubuntu/CentOS 系统上安装与配置Nginx 一.在线安装: Ubuntu:sudo apt-get install nginx CentOS: sudo yum install nginx ...

  6. linguistic相关

    Knowing a word means knowing both its sound and its meaning, while being able to use a word requires ...

  7. AOP原理

    AOP(面向切面编程):扩展功能时不修改源代码,采用横向抽取机制 纵向抽取机制: 横向抽取机制: 第一种情况: 第二种情况:

  8. C++之log4cpp库的使用

    log4..简介 log4..是基于log4j的一系列的c++移植版本,使用了log4j的模式结构,目前主要有以下几个版本: 1. log4cxx, 目前是到0.10.0版,Apache下的孵化项目, ...

  9. 回味经典——uboot1.1.6 之 第一阶段

    转自:http://blog.csdn.net/lizuobin2/article/details/52054293 最近打算移植一个比较新的 uboot 到开发板,回想起来上一次移植 uboot1. ...

  10. pdf2swf 转换时报This file is too complex to render- SWF only supports 65536 shapes at once

    ERROR   ID Table overflow ERROR   This file is too complex to render- SWF only supports 65536 shapes ...