Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1496

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.