HDU : Equations



// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <sstream>
#include <set>
#include <math.h>
#define pi acos(-1.0)
#define N 1000000
using namespace std;



int main ()
{
    int a, b, c, d;

    while ( scanf ("%d %d %d %d", &a, &b, &c, &d) != EOF ) {

        if ( (a > 0 && b > 0 && c > 0 && d > 0) || (a < 0 && b < 0 && c < 0 && d < 0) ) {
            printf ("0\n");
            continue;
        }

        int cnt = 0;
        map <int, int> right;
        int res;

        for ( int i = 1; i <= 100; i++ ) {
            for ( int j = 1; j <= 100; j++ ) {
                res = a * i * i + b * j * j;
                right [res]++;
            }
        }

        c *= -1;
        d *= -1;

        for ( int i = 1; i <= 100; i++ ) {
            for ( int j = 1; j <= 100; j++ ) {
                res = c * i * i + d * j * j;
                if ( right [res] != 0 )
                    cnt += right [res];
            }
        }

        printf ("%d\n", cnt * 16);
    }

    return 0;
}

// @END_OF_SOURCE_CODE

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s