Cod sursa(job #2590444)

Utilizator NicolaalexandraNicola Alexandra Mihaela Nicolaalexandra Data 27 martie 2020 22:48:07
Problema Dreptunghiuri Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("dreptunghiuri.in");
ofstream fout ("dreptunghiuri.out");
int n,m,i,j,k;

int main (){

    fin>>n>>m;

    long long sol = 0;
    for (i=1;i<n;++i)
        for (j=1;j<m;++j){

            /// fixez un punct de pe latime
            int cnt = 1;
            for (int k=1;k<i;++k){
                int b = -j;
                int c = k * i - k * k;
                int delta = b*b - 4*c;
                if (delta < 0)
                    continue;

                double root = sqrt(delta);
                if (root != (int)(root))
                    continue;

                int val = root;
                int x1 = j + val, x2 = j - val;

                if ( (x1&1) == 0 && (x1>>1) > 0 && (x1>>1) < j)
                    ++cnt;
                if (delta && (x2&1) == 0 && (x2>>1) > 0 && (x2>>1) < j)
                    ++cnt;
            }

            sol += 1LL * cnt * (n-i) * (m-j);

        }

    fout<<sol;

    return 0;
}