标签:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int T,x,y,ans,g,l1,r1,l2,r2; int init() { int x=0;char s=getchar();bool f=0; while(s<‘0‘||s>‘9‘){if(s==‘-‘)f=1;s=getchar();} while(s>=‘0‘&&s<=‘9‘){x=x*10+s-‘0‘;s=getchar();} if(f)return -x;return x; } void E_gcd(int a,int b) { if(b==0) { x=1;y=0;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=0; a=init();b=init();c=init(); c=-c; l1=init();r1=init();l2=init();r2=init(); if(a==0&&b==0) { if(c!=0||l1>r1||l2>r1) { printf("0\n"); continue; } long long an,li,ri; li=r1-l1+1;ri=r2-l2+1; an=li*ri; cout<<an<<endl; continue; } if(a==0) { y=c/b; if(y<l2||y>r2||c%b!=0) printf("0\n"); else printf("1\n"); continue; } if(b==0) { x=c/a; if(x<l1||x>r1||c%a!=0) printf("0\n"); else printf("1\n"); continue; } E_gcd(a,b); if(c%g!=0) { 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 0; }
标签:
原文地址:http://www.cnblogs.com/yanlifneg/p/5532019.html