题目描述

Having decided to invest in renewable energy, Byteasar started a solar panels factory. It appears that he has hit the gold as within a few days  clients walked through his door. Each client has ordered a single rectangular panel with specified width and height ranges.
The panels consist of square photovoltaic cells. The cells are available in all integer sizes, i.e., with the side length integer, but all cells in one panel have to be of the same size. The production process exhibits economies of scale in that the larger the cells that form it, the more efficient the panel. Thus, for each of the ordered panels, Byteasar would like to know the maximum side length of the cells it can be made of.
n组询问,每次问smin<=x<=smax, wmin<=y<=wmax时gcd(x, y)的最大值。

输入

The first line of the standard input contains a single integer N(1<=N<=1000): the number of panels that were ordered. The following   lines describe each of those panels: the i-th line contains four integers Smin,Smax,Wmin,Wmax(1<=Smin<=Smax<=10^9,1<=Wmin<=Wmax<=10^9), separated by single spaces; these specify the minimum width, the maximum width, the minimum height, and the maximum height of the i-th panel respectively.

输出

Your program should print exactly n lines to the standard output. The i-th line is to give the maximum side length of the cells that the i-th panel can be made of.

样例输入

4
3 9 8 8
1 10 11 15
4 7 22 23
2 5 19 24

样例输出

8
7
2
5


题解

数论

结论:区间$(l,r]$中出现$n$的倍数的充要条件是$\lfloor\frac rn\rfloor>\lfloor\frac ln\rfloor$。

于是可以枚举$i$,看是否在两段区间内都出现过。可以通过枚举商将时间复杂度将至$O(n\sqrt a)$。

注意在枚举商的时候要使用最后一个商与$b/i$和$d/i$相等的$last$值计算。

#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int T , a , b , c , d , i , last , ans;
scanf("%d" , &T);
while(T -- )
{
scanf("%d%d%d%d" , &a , &b , &c , &d);
for(i = 1 ; i <= b && i <= d ; i = last + 1)
{
last = min(b / (b / i) , d / (d / i));
if(b / last > (a - 1) / last && d / last > (c - 1) / last) ans = last;
}
printf("%d\n" , ans);
}
return 0;
}

【bzoj3834】[Poi2014]Solar Panels 数论的更多相关文章

  1. bzoj 3834 [Poi2014]Solar Panels 数论分块

    3834: [Poi2014]Solar Panels Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 367  Solved: 285[Submit] ...

  2. BZOJ3834[Poi2014]Solar Panels——分块

    题目描述 Having decided to invest in renewable energy, Byteasar started a solar panels factory. It appea ...

  3. BZOJ3834 [Poi2014]Solar Panels 【数论】

    题目链接 BZOJ3834 题解 容易想到对于\(gcd(x,y) = D\),\(d\)的倍数一定存在于两个区间中 换言之 \[\lfloor \frac{a - 1}{D} \rfloor < ...

  4. BZOJ3834 : [Poi2014]Solar Panels

    问题相当于找到一个最大的k满足在$[x_1,x_2]$,$[y_1,y_2]$中都有k的倍数 等价于$\frac{x_2}{k}>\frac{x_1-1}{k}$且$\frac{y_2}{k}& ...

  5. 【BZOJ3834】[Poi2014]Solar Panels 分块好题

    [BZOJ3834][Poi2014]Solar Panels Description Having decided to invest in renewable energy, Byteasar s ...

  6. [POI2014]Solar Panels

    题目大意: $T(T\le1000)$组询问,每次给出$A,B,C,D(A,B,C,D\le10^9)$,求满足$A\le x\le B,C\le y\le D$的最大的$\gcd(x,y)$. 思路 ...

  7. 【BZOJ】3834: [Poi2014]Solar Panels

    http://www.lydsy.com/JudgeOnline/problem.php?id=3834 题意:求$max\{(i,j)\}, smin<=i<=smax, wmin< ...

  8. BZOJ3834:Solar Panels (分块)

    题意 询问两个区间[smin,smax],[wmin,smax]中是否存在k的倍数,使得k最大 分析 将其转化成\([\frac{smin-1}k,\frac{smax}k],[\frac{wmin- ...

  9. BZOJ3833 : [Poi2014]Solar lamps

    首先旋转坐标系,将范围表示成矩形或者射线 如果范围是一条线,则将灯按y坐标排序,y坐标相同的按x坐标排序, 对于y相同的灯,f[i]=min(i,它前面灯发光时刻的第k[i]小值), 线段树维护,$O ...

随机推荐

  1. 【BZOJ4196】[NOI2015] 软件包管理器(树链剖分)

    点此看题面 大致题意: 有\(n\)个软件包,它们的依赖关系形成一棵树.现在,问你安装或卸载一个软件包,会影响多少个软件包的安装状态. 树链剖分 这道题应该是 树链剖分 算法比较入门的题目吧. 对于安 ...

  2. 01HTML

    1.认识HTML标记 2.元信息标记meta 2.1设置页面关键字 2.2设置页面说明 2.3定义编辑工具 2.4添加作者信息 2.5设置网页文字及语言 2.6设置网页的定时跳转 <html&g ...

  3. css代码

    #footr { background: #3e434a } #header #blogTitle { background: url("http://images.cnblogs.com/ ...

  4. 深入理解Java GC

    一.概述 GC(Carbage Collection)垃圾收集器,由JVM自动回收已死亡的对象垃圾. 这也是Java与C++等语言的主要区别之一. 二.如何确认对象已死 1. 引用计数算法 引用计数法 ...

  5. vue-cli npm run build 打包问题 webpack@3.6

    1, vue-router 路由 有两个模式 (mode) hash (默认模式) 使用URL来模拟一个完整的URL 但是没个URL都会带上 "#/'' 支持所有浏览器 这个模式使用 red ...

  6. SAP 日志管理

    现在项目上自开发的dialog程序越来越多,有很多敏感数据需要像SAP标准的业务一样,能看到所有的修改日志,要想实现日志的功能,有以下几个办法: 办法一.建一个日志表,在原有表的基础上,加上日期和时间 ...

  7. 关于在namanode上编写脚本控制DataNode的...

    脚本如下:(我的虚拟机名字分别为:wang201 wang 202 wang 203 wang 204) params=$@ i= ; i <= ; i++)) ; do echo ====== ...

  8. Missian指南三:创建一个Missian服务器(使用spring)

    在使用Missian时,spring是可选的,但是作者本人强烈推荐和Spring配合使用.Spring是一个伟大的项目,并且它不会对程序在运行时的效率带来任何损耗. Missian在服务器端依赖与Mi ...

  9. SoapUI(一)之webservice测试

    webservice测试需要具备的条件: 1.了解业务需求:如从客户端发送一个post请求给服务器,服务器将响应传给客户端. 2.需要一个明确的wsdl地址: 如天气预报的接口链接:http://ww ...

  10. A * B Problem Plus HDU - 1402 (FFT)

    A * B Problem Plus HDU - 1402 (FFT) Calculate A * B.  InputEach line will contain two integers A and ...