题目链接

BZOJ3834

题解

容易想到对于\(gcd(x,y) = D\),\(d\)的倍数一定存在于两个区间中

换言之

\[\lfloor \frac{a - 1}{D} \rfloor < \lfloor \frac{b}{D} \rfloor
\]

\[\lfloor \frac{c - 1}{D} \rfloor < \lfloor \frac{d}{D} \rfloor
\]

整除分块即可做到\(O(n\sqrt{max\{b\}})\)

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 100005,maxm = 100005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
int main(){
register int T = read(),a,b,c,d,M,ans,A,B,C,D;
while (T--){
a = read() - 1; b = read(); c = read() - 1; d = read();
M = max(b,d); ans = 1;
for (register int i = 1,nxt; i <= M; i = nxt + 1){
nxt = INF;
A = a / i,B = b /i,C = c / i,D = d / i;
if (A) nxt = min(nxt,a / A);
if (B) nxt = min(nxt,b / B);
if (C) nxt = min(nxt,c / C);
if (D) nxt = min(nxt,d / D);
if (A < B && C < D) ans = nxt;
}
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——分块

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

  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. Linux系统初探过程总结

    Linux系统初探的过程大约用了一周的时间,这周基本将Linux系统安装,PostgreSQL安装,Nginx服务器安装,ASP.NET Core应用部署都走了一遍.由于以前没有怎么接触和使用过Lin ...

  2. CF 675E Trains and Statistic

    草稿和一些题解而已 因为指针太恶心了 所以query决定还是要试试自己yy一下 #include<cstdio> #include<cstring> #include<i ...

  3. docker 下载安装与配置

    # mac离线安装dockerhttps://download.docker.com/mac/stable/24312/Docker.dmg # windows离线安装dockerhttp://mir ...

  4. yocto-sumo源码解析(十): ProcessServer.idle_commands

    这一节开始介绍ProcessServer.idle_commands,前面我们知道ProcessServer.main就是不停调用idle_commands()以获取可用的套接字描述符或者是文件描述符 ...

  5. Codeforces1084 | Round526Div2 | 瞎讲报告

    目录 A. The Fair Nut and Elevator B.Kvass and the Fair Nut C.The Fair Nut and String D.The Fair Nut an ...

  6. Python之并发编程-IO模型

    目录 一.IO模型介绍二.阻塞IO(blocking IO)三.非阻塞IO(non-blocking IO)四.多路复用IO(IO multiplexing)五.异步IO(Asynchronous I ...

  7. PowerDesgner的视图显示设置教程

    一.简介 PowerDesgner是一款实用的数据库原型设计软件,但一些新手往往会觉得不好上手,应小伙伴需要,整理了一下PowerDesgner的视图显示设置教程: 首先,PowerDesgner的数 ...

  8. java.util.ConcurrentModificationException: null

    是因为在map.foreach中又put新的值了 在map.foreach中可能是不可以增删改

  9. Scrum Meeting 10.29

    成员 今日活动 明日计划 用时 徐越 配置tomcat+eclipse 将上届后端代码迁移到服务器 4h 赵庶宏 与数据库连接的java代码学习及编写,测试代码 进行数据库的建立并学习数据库方面的知识 ...

  10. 20162328蔡文琛 大二week07

    20162328 2017-2018-1 <程序设计与数据结构>第7周学习总结 教材学习内容总结 树是非线性结构,其元素组织为一个层次结构. 树的度表示树种任意节点的最大子节点数. 有m个 ...