P3935 Calculating 整除分块
传送门
文章目录
- 题意:
- 思路:
题意:
思路:
我们设s(x)=∑i=1nf(x)s(x)=\sum_{i=1}^nf(x)s(x)=∑i=1nf(x),那么答案就是s(r)−s(l−1)s(r)-s(l-1)s(r)−s(l−1)。
容易发现,我们要求的f(x)f(x)f(x)实际上就是xxx的因子的个数,那么s(x)=∑i=1n∑d∣i1s(x)=\sum_{i=1}^n\sum_{d|i}1s(x)=∑i=1n∑d∣i1,我们改为枚举因子,即s(x)=∑i=1n⌊ni⌋s(x)=\sum_{i=1}^n\left \lfloor \frac{n}{i} \right \rfloors(x)=∑i=1n⌊in⌋,这个可以整除分块O(n)O(\sqrt n )O(n)求。
// Problem: P3935 Calculating
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P3935
// Memory Limit: 128 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=1000010,mod=998244353,INF=0x3f3f3f3f;
const double eps=1e-6;LL l,r;LL get(LL n) {LL ans=0;for(LL l=1,r;l<=n;l=r+1) {r=n/(n/l);ans+=(r-l+1)%mod*((n/l)%mod)%mod; ans%=mod;}return ans;
} int main()
{// ios::sync_with_stdio(false);
// cin.tie(0);LL ans=0;scanf("%lld%lld",&l,&r);ans+=get(r)-get(l-1); ans%=mod; ans+=mod; ans%=mod;printf("%lld\n",ans);return 0;
}
/**/
P3935 Calculating 整除分块相关推荐
- 洛谷 - P3935 - Calculating - 整除分块
https://www.luogu.org/fe/problem/P3935 求: \(F(n)=\sum\limits_{i=1}^{n}d(i)\) 枚举因子\(d\),每个因子\(d\)都给其倍 ...
- SDOI2015 约数个数和(莫比乌斯反演经典、双上限整除分块)超详细笔记
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 AcWing 1358. 约数个数和(莫比乌斯反演经典.双上限整除分块) #include <c ...
- luogu P3455 [POI2007]ZAP-Queries (莫比乌斯反演 + 整除分块)
整理的算法模板合集: ACM模板 题目传送门 本题中数据为5e4,我们只需要筛一次5e4就行了. 双倍经验的P4450 双亲数中数据达到了1e6,我们直接筛1e6的莫比乌斯函数有点不可取,因为只有一组 ...
- P2261 [CQOI2007]余数求和 整除分块
传送门 文章目录 题意: 思路: 题意: n,k≤1e9n,k\le1e9n,k≤1e9 思路: 考虑转换式子,∑i=1nkmodi=∑i=1n(k−⌊ki⌋∗i)=n∗k−∑i=1n⌊ki⌋∗i\s ...
- 【WC2014】时空穿梭【组合数】【莫比乌斯反演】【整除分块】【暴力多项式】
题意:TTT 组数据,给一个 nnn 维空间,第 iii 维大小为 [1,mi]∩Z[1,m_i]\cap \Z[1,mi]∩Z,求大小为 ccc 的严格偏序上升的共线点集个数.答案模 100071 ...
- 【NOI2016】循环之美【莫比乌斯反演】【整除分块】【杜教筛】【类杜教筛】
传送门 题意:给定n,m,kn,m,kn,m,k,求1≤x≤n,1≤y≤m1\leq x\leq n,1\leq y\leq m1≤x≤n,1≤y≤m时xyx \over yyx中数值不同的纯循环小 ...
- [CQOI2017] 小Q的表格(分块 + 整除分块 + 数学 + 前缀和)
problem luogu-P3700 solution f(a,b)=f(b,a)f(a,b)=f(b,a)f(a,b)=f(b,a) 意味着我们只用考虑半个棋盘的信息. b∗f(a,a+b)=(a ...
- P3235-[HNOI2014]江南乐【整除分块,SG函数】
正题 题目链接:https://www.luogu.com.cn/problem/P3235 题目大意 TTT组游戏,固定给出FFF.每组游戏有nnn个石头,每次操作的人可以选择一个数量不少于FFF的 ...
- AT2300-[ARC068C]Snuke Line【整除分块】
正题 题目链接: https://www.luogu.com.cn/problem/AT2300 https://atcoder.jp/contests/arc068/tasks/arc068_c 题 ...
最新文章
- win10下Git和Tortoise安装并使用VS15保存到码云
- java memcachedclient_memcached client — memcached client for java使用 | 学步园
- 判断出栈序列是否合法(c语言实现)
- OpenStack自动发现计算节点
- [mybatis]sqlSessionFactory.openSession()
- 在MySQL查询山东省男生信息_MySQL-查询
- php提前输出响应及注意问题
- ssh-keygen+ssh-copy-id无密码登录远程LINUX主机(转载)
- 网站常用色彩表(网络搜集整理)
- 开源视频云转码 m3u8_8种开源视频游戏
- 蒟蒻的网络流24题解题记
- 黑帽SEO网站优化常用的14种技巧
- minaRActivator三网完美解信号,支持IOS15.6
- 自学python书籍_自学python看什么书
- 毕业前三年如何拿到好绩效
- apache带宽配置
- 单选框(必选)功能的实现
- 什么是Python之禅?
- 适合户外运动的蓝牙耳机品牌有哪些呀?户外运动耳机排行榜
- 手机百度网页背景颜色设置_手机百度底色怎么变为黑色?
热门文章
- axure如何导出原件_axure导出_axure怎么导出流程图
- html页面阴影怎么做,html – 做弯曲阴影的最佳方式
- 这些全国各地甜点,你都吃过了吗?
- 导师都有哪些“秘密”没有告诉你?
- 惊了!日本街头出现透明公厕,竟有人排队抢着上!
- 左手菲尔兹右手突破奖,这个中国女婿其实是英国贵族?拿到300万奖金后他这样说……...
- 见识决定眼界,关注这些让你变得博学且有趣
- 快速掌握MATLAB应用,从这一步开始
- 深度学习 占用gpu内存 使用率为0_深度解析MegEngine亚线性显存优化技术
- html首页 slider图片切换效果,jQuery插件Slider Revolution实现响应动画滑动图片切换效果...