【牛客网235422 区间最大值】题解
2022/7/28 23:30:35
本文主要是介绍【牛客网235422 区间最大值】题解,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
题目地址
题目
思路
以下分数皆表示整除
\[\Large\max(n\bmod i)\\\Large=\max(n-\frac n i\times i)\\\Large=n+\max(-\frac n i\times i)\\\Large=n-\min(\frac n i \times i) \]显然,当 \(\frac n i\) 一定时,\(i\) 越小越好,所以可以把每个 \(\frac n i\) 求出来,然后数列分块取最小值即可
Code
// Problem: 区间最大值 // Contest: NowCoder // URL: https://ac.nowcoder.com/acm/contest/30896/A // Memory Limit: 524288 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> using namespace std; #define int long long inline int read(){int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+ (x<<3)+(ch^48);ch=getchar();}return x*f;} //#define M //#define mo //#define N int n, m, i, j, k, T; int l, r, ans; signed main() { // freopen("tiaoshi.in", "r", stdin); // freopen("tiaoshi.out", "w", stdout); n=read(); T=read(); while(T--) { l=read(); r=read(); ans=1e9; for(i=l; i<=r; i=(n/(n/i))+1) ans=min(ans, n/i*i); printf("%lld\n", n-ans); } return 0; }
总结
只要出现一个数反复除或模很多数,基本上就是数论分块了
这篇关于【牛客网235422 区间最大值】题解的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?