整除分块枚举。。。

真的没有想到会这么简单。

要使一个数 \(p\) 满足 条件, 则 存在\(x, y\), \(a<=x \times p<=b\ \&\&\ c<=y \times p <=d\)

把\(p\) 除掉 则

   \(\left\lceil\dfrac{a}{p}\right\rceil <=y <=\left\lfloor\dfrac{b}{p}\right\rfloor\)

   \(\left\lceil\dfrac{c}{p}\right\rceil <=y <=\left\lfloor\dfrac{d}{p}\right\rfloor\)

把向上取整变为向下取整

   \(\left\lfloor\dfrac{a+p-1}{p}\right\rfloor <= \left\lfloor\dfrac{b}{p}\right\rfloor\)

   \(\left\lfloor\dfrac{b+p-1}{p}\right\rfloor <= \left\lfloor\dfrac{d}{p}\right\rfloor\)

然后就变成了 :

  \(\left\lfloor\dfrac{a-1}{p}\right\rfloor < \left\lfloor\dfrac{b}{p}\right\rfloor\)

  \(\left\lfloor\dfrac{b-1}{p}\right\rfloor < \left\lfloor\dfrac{d}{p}\right\rfloor\)

最后整除分块。 只需按照 \(b/p\)和\(d/p\) 相同时进行分类。 这样能使 \(b/p\) 和 \(d/p\)相等的同时 \(c/p\) 和 \(d/p\)尽量小, 更可能满足条件

#include<cstdio>
#include<cstring>
#include<algorithm>
#define rd read()
#define R register
using namespace std; inline int read() {
int X = 0, p = 1; char c = getchar();
for (; c > '9' || c < '0'; c = getchar())
if (c == '-') p = -1;
for (; c >= '0' && c <= '9'; c = getchar())
X = X * 10 + c - '0';
return X * p;
} inline void cmax(int &A, int B) {
if (A < B) A = B;
} inline int cmin(int A, int B) {
return A > B ? B : A;
} void work() {
int ans = 1;
int a = rd - 1, b = rd, c = rd - 1, d = rd;
for (R int i = 1, j = 1, up = cmin(b, d); i <= up; i = j + 1) {
j = cmin(b / (b / i), d / (d / i));
if (b / j > a / j && d / j > c / j) cmax(ans, j);
}
printf("%d\n", ans);
} int main()
{
int n = rd;
for (; n; --n) work();
}

最新文章

  1. Kanzi Q&amp;A
  2. git参考资料
  3. HDU 4349 Xiao Ming&#39;s Hope lucas定理
  4. python在window下的Nginx部署
  5. RabbitMQ系列二(构建消息队列)
  6. 解决sharepoint 2010 用户配置文件同步服务 正在启动
  7. mysqld --debug-sync
  8. 读书笔记 effective c++ Item 5 了解c++默认生成并调用的函数
  9. js如何获取地址栏的参数
  10. python爬虫爬取人人车(二手车)、利用padas、matplotlib生成图表,将信息打成csv格式
  11. maven 阿里云仓库配置
  12. 关于ajax的content-download时间过慢问题的解决方案与思考
  13. ad network
  14. patch 28729262
  15. 利用pyinstaller 打包Python文件
  16. Linux配置日志服务器
  17. cocos2d-x 清空缓存
  18. Qt选择文件对话框-中文路径-转std::string
  19. day2、购物商城
  20. ipad4没有声音提示消息

热门文章

  1. matlab-逻辑回归二分类(Logistic Regression)
  2. Jmeter5.1.1+python调用python脚本
  3. redis 模糊删除key
  4. redis 安装启动
  5. Head First Java.(第2版)
  6. ios 信任charles https 证书
  7. ReactiveX 学习笔记(28)使用 RxJS + React.js 进行 GUI 编程
  8. 关于Eclipse for Python
  9. VirtualBox安装Ubuntu16.04过程
  10. nginx stream module on mt7621(newifi3 d2) with openwrt 18.06.2