HDU - 1496 Equations
Consider equations having the following form:
a*x1^2+b*x2^2+c*x3^2+d*x4^2=0
a, b, c, d are integers from the interval [-50,50] and any of them cannot be 0.
It is consider a solution a system ( x1,x2,x3,x4 ) that verifies the equation, xi is an integer from [-100,100] and xi != 0, any i ∈{1,2,3,4}.
Determine how many solutions satisfy the given equation.
InputThe input consists of several test cases. Each test case consists of a single line containing the 4 coefficients a, b, c, d, separated by one or more blanks.
End of file.OutputFor each test case, output a single line containing the number of the solutions.
Sample Input
1 2 3 -4 1 1 1 1
Sample Output
39088 0
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 5 using namespace std; 6 7 int he[2000005],ji[105]; 8 9 int main() 10 { 11 for(int i=1;i<=100;i++) 12 ji[i]=i*i; 13 int a,b,c,d; 14 while(~scanf("%d %d %d %d",&a,&b,&c,&d)) 15 { 16 memset(he,0,sizeof(he)); 17 int sum=0; 18 for(int i=1;i<=100;i++) 19 for(int j=1;j<=100;j++) 20 he[a*ji[i]+b*ji[j]+1000000]++; 21 for(int i=1;i<=100;i++) 22 for(int j=1;j<=100;j++) 23 sum+=he[-(c*ji[i]+d*ji[j])+1000000]; 24 printf("%d\n",sum*16); 25 } 26 27 28 return 0; 29 }