Idea: Mainly convert the equation into the left and right parts. Use a hash array to store the left value first. Then, when calculating the value on the right, you only need to address it ,,,,
Equations
Time Limit: 6000/3000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 2456 accepted submission (s): 969
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
Authorll
AC code:
# Include <iostream> # include <string. h> # define n 1000000 using namespace STD; char hash [2 * n + 100]; int main () {int A, B, C, D; while (~ Scanf ("% d", & A, & B, & C, & D )) {If (a> 0 & B> 0 & C> 0 & D> 0) | (A <0 & B <0 & C <0 & D <0) // pruning ,,,,,,, {printf ("0 \ n"); continue;} memset (hash, 0, sizeof (hash); For (INT I = 1; I <= 100; ++ I) for (Int J = 1; j <= 100; ++ J) hash [1000000 + A * I * I + B * j] ++; int sum = 0; For (INT I = 1; I <= 100; ++ I) for (Int J = 1; j <= 100; ++ J) sum + = hash [000000-c * I * I-d * j]; printf ("% d \ n", 16 * sum);} return 0 ;}