题目大意:

给出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. jQuery操作Table学习总结[转]

    <style type="text/css">       .hover       {                  }    </style>< ...

  2. Perl6 Bailador框架(7):模版编写

    先看一个例子: use v6; use Bailador; my $data = ' <form action="", method="get"> ...

  3. imx6设备树pinctrl解析【转】

    转自:http://blog.csdn.net/michaelcao1980/article/details/50730421 版权声明:本文为博主原创文章,未经博主允许不得转载. 最近在移植linu ...

  4. 内存分配器memblock【转】

    转自:http://blog.csdn.net/kickxxx/article/details/54710243 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 背景 Data ...

  5. 《LINUX3.0内核源代码分析》第二章:中断和异常 【转】

    转自:http://blog.chinaunix.net/uid-25845340-id-2982887.html 摘要:第二章主要讲述linux如何处理ARM cortex A9多核处理器的中断.异 ...

  6. 64_l3

    libguac-client-ssh-0.9.13-3.20170521git6d2cfda...> 23-May-2017 09:58 64570 libguac-client-ssh-0.9 ...

  7. Centos_Lvm_Create pv vg lv and mount

    re-scan new disks without restarting CentOS re-scan new disks(/dev/sdc): #ls /sys/class/scsi_host/ h ...

  8. xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance(xsi:schemaLocation详解)

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"中xsi的意思是 :本xml文件中要用到某些来自xsi代表的“http:/ ...

  9. An unhandled exception of type 'System.TypeInitializationException' occurred in System.ServiceModel.dll

    异常“ An unhandled exception of type 'System.TypeInitializationException' occurred in System.ServiceMo ...

  10. CF625D Finals in arithmetic-构造,贪心,细节

    题目链接:http://codeforces.com/contest/625/problem/D 题意: 给你一个数字字符串s,长度1e6,算是一个大数吧,让你找到一个x,使得,x加上  逆转(x)= ...