http://acm.hdu.edu.cn/showproblem.php?pid=1496
Problem Descriptionconsider equations having the following form:
A*x1^2+b*x2^2+c*x3^2+d*x4^2=0
A, B, C, D is integers from the interval [ -50,50] and any of them cannot is 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 containing the 4 coefficients a, B, C, D, separated by one or more blanks.
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
This problem can be enumerated in two points, but the hash is simpler.
We can guarantee that a*i*i, B*j*j,-c*i*i,-d*j*j is a positive integer, so we could use an array to represent the
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm>using namespace Std;int hash[1000000*2+7];int A,b,c,d;int Main () { while (~scanf ("%d%d%d%d", &a,&b,&c,&d)) { memset (hash,0,sizeof (hash)); for (int i=1;i<=100;i++) {for (int j=1;j<=100;j++) { hash[i*i*a+j*j*b+1000000]++; } } int sum=0; for (int i=1;i<=100;i++) {for (int j=1;j<=100;j++) { sum+=hash[-i*i*c-j*j*d+1000000]; } } printf ("%d\n", sum*16); } return 0;}
HDU 1496 hash+ Violence