Number of Solving Equations
The clever hash mainly refers to the size range of a, B, c, and d x.
View Code
# Include <iostream>
# Include <algorithm>
Using namespace std;
Int hash1 [3000005];
Int main ()
{
Int a, B, c, d, x1, x2, x3, x4, ans;
While (~ Scanf ("% d", & a, & B, & c, & d ))
{
If (a> 0 & B> 0 & c> 0 & d> 0 | a <0 & B <0 & c <0 & d <0) // It must be the same number and cannot be resolved. This timeout occurs on the wood.
{
Puts ("0 ");
Continue;
}
Memset (hash1, 0, sizeof (hash1 ));
Ans = 0;
For (x1 = 1; x1 <101; x1 ++) // hash converts a four-fold loop into a double loop, greatly reducing the complexity
For (x2 = 1; x2 <101; x2 ++)
Hash1 [a * x1 * x1 + B * x2 * x2 + 2000000] ++;
For (x3 = 1; x3 <101; x3 ++)
For (x 4 = 1; x 4 <101; x 4 ++)
Ans + = hash1 [(0-(c x 3x3 + d x 4x4) + 2000000];
Ans * = 16;
// Because the difference between positive and negative numbers does not affect the effect of x square, the positive number is enumerated directly, and then multiplied by the 4 power of 2, indicating the combination of positive and negative
Printf ("% d \ n", ans );
}
Return 0;
}