Equations
Time Limit: 6000/3000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 5226 accepted submission (s): 2079
Problem descriptionconsider 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 blks.
End of file.
Outputfor each test case, output a single line containing the number of the solutions.
Sample Input
1 2 3 -41 1 1 1
Sample output
390880
Hash Table basics:
# Include <stdio. h >#include <algorithm> # define M 2000004int hash [m]; int main () {int A, B, C, D; int I, j; int sum, s [101]; for (I = 1; I <= 100; I ++) s [I] = I * I; while (~ Scanf ("% d", & A, & B, & C, & D )) {If (a> 0 & B> 0 & C> 0 & D> 0) | (A <0 & B <0 & C <0 & D <0) {printf ("0 \ n"); continue;} sum = 0; memset (hash, 0, sizeof (hash); for (I = 1; I <= 100; I ++) for (j = 1; j <= 100; j ++) hash [A * S [I] + B * s [J] + M/2] ++; // M/2 prevents negative subscripts. For (I = 1; I <= 100; I ++) for (j = 1; j <= 100; j ++) sum + = hash [-(C * s [I] + D * s [J]) + M/2]; // What do you think! Printf ("% d \ n", sum * 16);} return 0 ;}