codevs 1213 解的个数(我去年打了个表 - -)
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int T,x,y,ans,g,l1,r1,l2,r2;
int init()
{
int x=;char s=getchar();bool f=;
while(s<''||s>''){if(s=='-')f=;s=getchar();}
while(s>=''&&s<=''){x=x*+s-'';s=getchar();}
if(f)return -x;return x;
}
void E_gcd(int a,int b)
{
if(b==)
{
x=;y=;g=a;
}
else
{
E_gcd(b,a%b);
int tmp=x;
x=y;
y=tmp-a/b*y;
}
}
int main()
{
int a,b,c,i,j;
T=init();
while(T--)
{
ans=;
a=init();b=init();c=init();
c=-c;
l1=init();r1=init();l2=init();r2=init();
if(a==&&b==)
{
if(c!=||l1>r1||l2>r1)
{
printf("0\n");
continue;
}
long long an,li,ri;
li=r1-l1+;ri=r2-l2+;
an=li*ri;
cout<<an<<endl;
continue;
}
if(a==)
{
y=c/b;
if(y<l2||y>r2||c%b!=)
printf("0\n");
else
printf("1\n");
continue;
}
if(b==)
{
x=c/a;
if(x<l1||x>r1||c%a!=)
printf("0\n");
else
printf("1\n");
continue;
}
E_gcd(a,b);
if(c%g!=)
{
printf("0\n");
continue;
}
int s=c/g;
x*=s;y*=s;
int ai=a/g;
int bi=b/g;
if(x<l1)
{
while(x<l1)
{
x+=bi;y-=ai;
}
for(i=x;i<=r1;i+=bi,y-=ai)
if(y>=l2&&y<=r2)
ans++;
}
else if(x>r1)
{
while(x>r1)
{
x-=bi;y+=ai;
}
for(i=x;i>=l1;i-=bi,y+=ai)
if(y>=l2&&y<=r2)
ans++;
}
else
{
int yi=y;
for(i=x;i<=r1;i+=bi,yi-=ai)
if(yi>=l2&&yi<=r2)
ans++;
yi=y+ai;
for(i=x-bi;i>=l1;i-=bi,yi+=ai)
if(yi>=l2&&yi<=r2)
ans++;
}
printf("%d\n",ans);
}
return ;
}
codevs 1213 解的个数(我去年打了个表 - -)的更多相关文章
- 扩展gcd codevs 1213 解的个数
codevs 1213 解的个数 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知整数x,y满足如下面的条件: ax+by ...
- codevs 1213 解的个数
1213 解的个数 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知整数x,y满足如下面的条件: ax+by+c = ...
- Codevs 1213 解的个数(exgcd)
1213 解的个数 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知整数x,y满足如下面的条件: ax+by+c=0 p< ...
- 解的个数(codevs 1213)
题目描述 Description 已知整数x,y满足如下面的条件: ax+by+c = 0 p<=x<=q r<=y<=s 求满足这些条件的x,y的个数. 输入描述 Input ...
- n元线性方程非负整数解的个数问题
设方程x1+x2+x3+...+xn = m(m是常数) 这个方程的非负整数解的个数有(m+n-1)!/((n-1)!m!),也就是C(n+m-1,m). 具体解释就是m个1和n-1个0做重集的全排列 ...
- codevs1213 解的个数
题目描述 Description 已知整数x,y满足如下面的条件: ax+by+c = 0 p<=x<=q r<=y<=s 求满足这些条件的x,y的个数. 输入描述 Input ...
- P1098 方程解的个数
题目描述 给出一个正整数N,请你求出x+y+z=N这个方程的正整数解的组数(1<=x<=y<=z<1000).其中,1<=x<=y<=z<=N . 输入 ...
- PE文件格式详解,第三讲,可选头文件格式,以及节表
PE文件格式详解,第三讲,可选头文件格式,以及节表 作者:IBinary出处:http://www.cnblogs.com/iBinary/版权所有,欢迎保留原文链接进行转载:) 一丶可选头结构以及作 ...
- HDU1573 线性同余方程(解的个数)
X问题 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- 将日志写入EventLog
将日志写入EventLog 面向Windows的编程人员应该不会对Event Log感到陌生,以至于很多人提到日志,首先想到的就是EventLog.EventLog不仅仅记录了Windows系统自身针 ...
- Oracle数据库基础知识_字符串操作相关2
6.LPAD,RPAD 作用:左/右边的字符串填充一些特定的字符语法: LPAD(string , n, [pad_String]) string:可是字符或者参数 ...
- iOS开发之——巧用反射机制
1.应用场景——自定义UITabBarController的TabBar视图 (1)隐藏TabBar视图 一般我们选择自定义TabBar视图有两种方式.1是将tabBar视图隐藏;2是将TabBar视 ...
- A Statistical View of Deep Learning (II): Auto-encoders and Free Energy
A Statistical View of Deep Learning (II): Auto-encoders and Free Energy With the success of discrimi ...
- jQuery--Promise object
http://blog.mediumequalsmessage.com/promise-deferred-objects-in-javascript-pt2-practical-use http:// ...
- MYSQL的binary解决mysql数据大小写敏感问题 《转载》
BINARY不是函数,是类型转换运算符,它用来强制它后面的字符串为一个二进制字符串,可以理解为在字符串比较的时候区分大小写如下:mysql> select binary 'ABCD'='abcd ...
- Delphi重载,覆盖,多态
一.override 重载 type TFigure = class procedure Draw; virtual;//(我的理解是)父类中可以使用父类的,子类中使用子类的.与“四”是有区别的. e ...
- Unity 动态载入Panel并实现淡入淡出
unity版本:4.5 NGUI版本:3.6.5 参考链接:http://tieba.baidu.com/p/3206366700,作者:百度贴吧 水岸上 动态载入NGUI控件,这里用Panel为例说 ...
- 【转】onPrepareOptionsMenu 和onCreateOptionsMenu 的区别
原文网址:http://blog.csdn.net/allenjy123/article/details/7467084 @Override public boolean onCreateOption ...
- SharePoint Server 2007 Enterprise Key
正式版 key SN: Tkjcb-3wkhk-2ty2t-qymk2-9xm2y 这个版本也是通过Key来区分是否是测试版还是正式版的 也就是说你输入正式版的Key他就是正式版,输入Enterpri ...