Time Limit: 10 Sec  Memory Limit: 256 MB
Submit: 140  Solved: 48
[Submit][Status][Discuss]

Description

给出a,b,c,x1,x2,y1,y2,求满足ax+by+c=0,且x∈[x1,x2],y∈[y1,y2]的整数解有多少对?

Input

第一行包含7个整数,a,b,c,x1,x2,y1,y2,整数间用空格隔开。
a,b,c,x1,x2,y1,y2的绝对值不超过10^8。

Output

输出整数解有多少对?

Sample Input

1 1 -3 0 4 0 4

Sample Output

4

HINT

 

Source

 
 
一眼就能看出是扩欧
利用扩欧的通项公式求出上下边界进行处理
注意特殊情况的判断
注意这里

一定要先乘再除

mmp调了一晚上拍了n组数据都没拍出错误来。。

#include<iostream>
#include<cstdio>
#include<cmath>
#define LL long long
using namespace std;
const LL MAXN=1e6+;
LL a,b,c,x1,x2,yy1,y2,x,y;
LL exgcd(LL a,LL b,LL &x,LL &y) {
if(b==){x=,y=;return a;}
LL r=exgcd(b,a%b,x,y),tmp;
tmp=x,x=y,y=tmp-a/b*y;
return r;
}
LL min(LL a,LL b){return a<b?a:b;}
LL max(LL a,LL b){return a>b?a:b;}
int main()
{
cin>>a>>b>>c>>x1>>x2>>yy1>>y2;c=-c;
if(a==&&b==) {
if(c==) {printf("%lld",(LL)(x2-x1+)*(y2-yy1+));return ;}
else {printf("");return ;}
}
if(a==){
if(c%b) {printf("");return ;}
if(c/b>=yy1&&c/b<=y2) {printf("%lld",x2-x1+);return ;}
else {printf("");return ;}
}
if(b==) {
if(c%a) {printf("");return ;}
if(c/a>=x1&&c/a<=x2) {printf("%lld",y2-yy1+);return ;}
else {printf("");return ;}
}
LL r=exgcd(a,b,x,y);
b=b/r;a=-a/r;//利用公式构造增量
if(c%r) {printf("");return ;}
x=x*c/r;y=y*c/r;
LL xlower,xupper,ylower,yupper;
if(b>) xlower=ceil( (double)(x1-x)/b ) , xupper=floor( (double)(x2-x)/b );
if(b<) xlower=ceil( (double)(x2-x)/b ) , xupper=floor( (double)(x1-x)/b );
if(a>) ylower=ceil( (double)(yy1-y)/a ) , yupper=floor( (double)(y2-y)/a );
if(a<) ylower=ceil( (double)(y2-y)/a ) , yupper=floor( (double)(yy1-y)/a );
LL ans=max(, min(xupper,yupper) - max(xlower,ylower) + );
printf("%lld",ans); return ;
} //1 5 -3 -123 40 -567 41
 
 

最新文章

  1. ajax 异步加载显示等待效果
  2. QQ左侧滑动显示
  3. Android--&gt;Genymotion虚拟机(模拟器)的配置
  4. python 类中staticmethod,classmethod,普通方法
  5. ecshop缓存清理-限制或禁用ECShop缓存
  6. new总结
  7. (转)resize扩展
  8. Namespace declaration statement has to be the very first
  9. auto 和 decltype (C++11 新增)
  10. iOS设计模式——MVC(Model-View-Controller)
  11. OkHttp基本使用
  12. doT.js——前端javascript模板引擎问题备忘录
  13. MySQL ProxySQL相关维护说明
  14. Eclipse拷贝动态的web工程修改context root的值
  15. 秒懂HTTPS
  16. nginx下后端节点realserverweb健康检测模块ngx_http_upstream_check_module
  17. [HNOI2009]最小圈 (二分答案+负环)
  18. day_10 py 字典
  19. o(1), o(n), o(logn), o(nlogn)算法复杂度
  20. Linux查看文件安装路径与文件所在路径

热门文章

  1. 在cncc的最后几天的笔记
  2. ViewPager设置不能滚动
  3. WebSocket handshake: Unexpected response code: 404
  4. Service和Servlet的区别
  5. python 代码编写规范
  6. [NOI2016]优秀的拆分(SA数组)
  7. 【uva 1025】A Spy in the Metro
  8. Spring Boot学习总结(1)——Spring Boot入门
  9. C++归并算法
  10. WEB前端,混合排版,有的宽有的窄,滚动会出现空白处,怎么办。