E:方程式

题目:

Description

Consider equations having the following form: a*x1*x1 + b*x2*x2 + c*x3*x3 + d*x4*x4 = 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.

Input

The 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 blanks.

Output

or each test case, output a single line containing the number of the solutions.

Sample Input

1 2 3 -4

1 1 1 1

Sample Output

39088

0

代码:

 

#include <stdio.h>
#include <stdlib.h>
int a[10000],b[10000];
int cmp ( const void *a , const void *b )
{
return *(int *)a - *(int *)b;
}
int main()
{
    int x[4],i,j,k,count,t;
    while(scanf("%d%d%d%d",&x[0],&x[1],&x[2],&x[3])!=EOF)
    {
               for(k=0,i=1;i<=100;i++)
               {
                                          for(j=1;j<=100;j++)
                                          {
                                                 a[k]=x[0]*i*i+x[1]*j*j;
                                                 b[k]=-1*(x[2]*i*i+x[3]*j*j);
                                                 k++;
                                          }       
               }
               qsort(a,10000,sizeof(a[0]),cmp);//快排
               qsort(b,10000,sizeof(b[0]),cmp);
               count=i=j=0;
               while(i<k && j<k)
               {
                         if(a[i]<b[j]) i++;
                         else if(a[i]>b[j]) j++;
                         else
                         {
                             t=j+1;
                             count++;
                             while(t<k && a[i]==b[t]) {count++;t++;}
                             i++;
                         }
               }
               printf("%d\n",count*16);
    }
    return 0;
}

首发:http://www.iwebtrados.com.cn/post/363.html

你可能感兴趣的:(E:方程式)