题目大意:

给出T组询问,每组询问给出四个数a,b,c,d,每次询问满足a<=x<=b,c<=y<=d的gcd(x,y)的最大值

首先可以想到如果存在gcd(x,y)=k,那么就一定要满足b/k>(a-1)/k&&d/k>(c-1)/k。

而n/k的k取法只有√n种,直接枚举即可。

//by zykykyk
#include<cstdio>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#define rg register
#define il inline
#define vd void
#define ll long long
#define For(i,x,y) for (rg int i=(x);i<=(y);i++)
#define Dow(i,x,y) for (rg int i=(x);i>=(y);i--)
#define cross(i,k) for (rg int i=first[k];i;i=last[i])
using namespace std;
il ll max(ll x,ll y){return x>y?x:y;}
il ll min(ll x,ll y){return x<y?x:y;}
il ll read(){
ll x=;int ch=getchar(),f=;
while (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=getchar();
if (ch=='-'){f=-;ch=getchar();}
while (isdigit(ch)){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
}
int T,a,b,c,d,A,B,C,D,ans;
int main(){
T=read();
while (T--){
a=read(),b=read(),c=read(),d=read(),ans=;
int l=max(max(sqrt(a-),sqrt(b)),max(sqrt(c-),sqrt(d)));
For(i,,l){
int B=b/i,A=(a-)/i,D=d/i,C=(c-)/i;
if (B>A&&D>C) ans=max(ans,i);
if (A)
if (b/A>(a-)/A&&d/A>(c-)/A) ans=max(ans,A);
if (B)
if (b/B>(a-)/B&&d/B>(c-)/B) ans=max(ans,B);
if (C)
if (b/C>(a-)/C&&d/C>(c-)/C) ans=max(ans,C);
if (D)
if (b/D>(a-)/D&&d/D>(c-)/D) ans=max(ans,D);
}
printf("%d\n",ans);
}
}

Luogu P3579 [POI2014]PAN-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 分块好题

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

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

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

  4. 【bzoj3834】[Poi2014]Solar Panels 数论

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

  5. Luogu P3577 [POI2014]TUR-Tourism

    Luogu P3577 [POI2014]TUR-Tourism 题目链接 题目大意:给出一张\(n\)个点,\(m\)条边的无向图,保证任意两点之间没有点数超过\(10\)的简单路径.选择第\(i\ ...

  6. luogu P3567 [POI2014]KUR-Couriers

    二次联通门 : luogu P3567 [POI2014]KUR-Couriers MMP 指针 RE + MLE + WA..... 不得已...向黑恶的数组实力低头 /* 指针 */ #inclu ...

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

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

  8. 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}& ...

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

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

随机推荐

  1. JS高级之面试必须知道的几个点

    1.函数的3种定义方法 1.1 函数声明 //ES5 function getSum(){} function (){}//匿名函数 //ES6 ()=>{}//如果{}内容只有一行{}和ret ...

  2. CRB and Candies(组合数学+求逆元+lcm)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5407 题目: Problem Description CRB has N different cand ...

  3. 27、简述redis的有哪几种持久化策略及比较?

    Redis 提供了多种不同级别的持久化方式: RDB 持久化可以在指定的时间间隔内生成数据集的时间点快照(point-in-time snapshot). AOF 持久化记录服务器执行的所有写操作命令 ...

  4. DIV+CSS左右列高度自适应问题

    其实解决DIV+CSS左右两列高度自适应的方法就是要注意两点:一是在最外层加上overflow:hidden,然后在左边列加上margin-bottom:-9999px;padding-bottom: ...

  5. FIS3 大白话【一】

    1.fis3可以用fis.set进行一些全局的配置,包括忽略文件.文件后缀处理类型.源码过滤等等,用fis3.get可以得到配置信息,详见: http://fis.baidu.com/fis3/doc ...

  6. 33.Search in Rotated Sorted Array---二分变形---《剑指offer》面试题8

    题目链接 题目大意:在一个旋转数组中,判断给定的target是否存在于该旋转数组中.数组中没有重复数值.例子如下: 法一:二分.确定中间元素之后,就要判断下一步是遍历左数组还是遍历右数组.如果左数组有 ...

  7. RSA加密解密与加签验签

    RSA公钥加密算法是1977年由罗纳德·李维斯特(Ron Rivest).阿迪·萨莫尔(Adi Shamir)和伦纳德·阿德曼(Leonard Adleman)一起提出的.1987年7月首次在美国公布 ...

  8. [ Python ] 文件的读写操作

    1. 文件读写操作 读写文件是最常见的 IO 操作, Python 内置了读写文件的函数.在磁盘上读写文件的功能是由操作系统提供的,所以读写文件是请求操作系统打开一个文件对象(通常称为文件描述符),然 ...

  9. 关于 拼接 url 连接 参数的问题(爬虫)。

    比如这里 我找的 后台请求的json的链接: 第一页: http://www.igoldenbeta.com:8080/cn-jsfund-server-mobile/bkt/api?appkey=1 ...

  10. C#.Net实体代码生成工具(EntitysCodeGenerate)的使用及.NET中的ORM实现

    1 引言 目前大多数项目或产品都使用关系型数据库实现业务数据的存储,这样在开发过程中,常常有一些业务逻辑需要直接用写SQL语句实现,但这样开发的结果是:遍地布满SQL语句.这些藕合较高的SQL语句给系 ...