Equations
http://acm.hdu.edu.cn/showproblem.php?pid=1496
Time limit:6000/3000 MS (java/others)
Memory limit:32768/32768 K (java/others)
Problem Description
Consider equations has 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 ,] and any of the them cannot be 0. It is consider a solution a system (X1,X2,X3,X4) that verifies the equation, and the XI was an integer from [ -100,100] and Xi!= 0, any i∈{1,2,3,4}. Determine how many solutions satisfy the given equation.
Input
The input consists of several test cases. Each test case consists of the "a single" containing the 4 coefficients a, B, C, D, separated by one or more blanks. End of file.
Output
For 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
Author
LL
Source
"2006 Campus Culture Activity Month" "The Anniversary Cup" University student Program Design Competition and Hangzhou University of the fourth College student Program Design Competition
This article URL address: http://www.bianceng.cn/Programming/sjjg/201410/45517.htm
Idea: First, the violence will be tle, so divide the 4 numbers into 2 and 2 (read the challenge design contest for this). Noting that the range size of the a*x1^2+b*x2^2 is 2000000, we might as well traverse the first two numbers, compute and record an array hash[], iterate over the two numbers, and find them directly in hash[] so that the complexity is O (n^2) (n=100)
Complete code:
/*187ms,8044kb*/
#include <cstdio>
#include <cstring>
const int MAXN = 1000000;
int hash[2 * MAXN + 5];
int main ()
{
int A, B, C, D, I, J;
Long ans;
while (~SCANF ("%d%d%d%d", &a, &b, &c, &d))
{
if (a > 0 && B > 0 && C > 0 && d > 0 | | A < 0 && b < 0 && C < 0 && D < 0)
{
puts ("0");
Continue;
}
memset (hash, 0, sizeof (hash));
for (i = 1; I <=-++i) for
(j = 1; J <=; ++j)
++hash[a * I * i + b * J * j + MAXN];
ans = 0L;
for (i = 1; I <=-++i) for
(j = 1; J <=; ++j)
ans + = hash[-c * I * i-d * J * j + MAXN];
printf ("%i64d\n", ans << 4);
}