题目描述

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. Aizu 2170 Marked Ancestor(并查集变形)

    寻找根节点很容易让人联想到DisjointSet,但是DisjointSet只有合并操作, 所以询问离线倒着考虑,标记会一个一个消除,这时候就变成合并了. 因为询问和查询的时间以及标记生效的时间有关, ...

  2. iOS 制作表格 (数据源控制行,列数)

    记得去年面试的过程中,有一个面试官问我怎么制作表格.由于之前也没有做过,当时有点懵逼,今天想起来了,就用tableview制作了一个,望不要有人像我一样掉坑了, 直接上代码: // // ViewCo ...

  3. Problem D: 双向冒泡排序

    Problem D: 双向冒泡排序 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 447  Solved: 197[Submit][Status][We ...

  4. 小波变换(wavelet transform)的通俗解释(一)

    小波变换 小波,一个神奇的波,可长可短可胖可瘦(伸缩平移),当去学习小波的时候,第一个首先要做的就是回顾傅立叶变换(又回来了,唉),因为他们都是频率变换的方法,而傅立叶变换是最入门的,也是最先了解的, ...

  5. thinkcmf5 iis+php重写配置

    TP在本机运行非常好,谁想到服务器上后,连http://www.***.com/wap/login/index都404错误了, 中间的郁闷过程不表. 解决方案分两步: 第一步: 下载rewrite_2 ...

  6. php扩展开发-函数

    我们首先找到快速上手文章里面关于函数定义的代码,以此说明然后开发PHP的函数 //php_myext.h PHP_FUNCTION(myext_hello);//函数申明,所有在myext.c文件定义 ...

  7. JZOJ 5197. 【NOIP2017提高组模拟7.3】C

    5197. [NOIP2017提高组模拟7.3]C Time Limits: 1000 ms  Memory Limits: 262144 KB  Detailed Limits   Goto Pro ...

  8. python3.7 os模块

    #!/usr/bin/env python __author__ = "lrtao2010" #python3.7 os模块 #os模块是与操作系统交互的一个接口 # os.get ...

  9. 权限组件(11):基于formset实现批量增加

    效果图: 增加页面: 编辑页面: 因为后面要对权限进行批量操作,所以先用这个示例演示下如何实现批量操作 数据库 from django.db import models class Menu(mode ...

  10. linux shell 单双引号区别

    简要总结: 单引号: 可以说是所见即所得:即将单引号内的内容原样输出,或者描述为单引号里面看见的是什么就会输出什么. 双引号: 把双引号内的内容输出出来:如果内容中有命令,变量等,会先把变量,命令解析 ...