Cod sursa(job #1754425)

Utilizator alexandra_udristoiuUdristoiu Alexandra Maria alexandra_udristoiu Data 8 septembrie 2016 10:03:05
Problema Dreptunghiuri Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.32 kb
#include<fstream>
#include<cmath>
using namespace std;
int n, m, L, C, a, delta, x, r;
long long sol;
int d[405][405];
ifstream fin("dreptunghiuri.in");
ofstream fout("dreptunghiuri.out");
int main(){
    fin>> n >> m;
    n--;
    m--;
    for(L = 1; L <= n; L++){
        for(C = 1; C <= m; C++){
            for(a = 1; a < L; a++){
                delta = C * C - 4 * (L * a - a * a);
                if(delta < 0){
                    continue;
                }
                r = sqrt(delta * 1.0);
                if(r * r != delta){
                    continue;
                }
                if(r == 0){
                    if(C % 2 == 0){
                        d[L][C]++;
                    }
                }
                else{
                    x = C - r;
                    if(x % 2 == 0 && x / 2 >= 1 && x / 2 < C){
                        d[L][C]++;
                    }
                    x = C + r;
                    if(x % 2 == 0 && x / 2 >= 1 && x / 2 < C){
                        d[L][C]++;
                    }
                }
            }
            d[L][C]++;
        }
    }
    for(L = 1; L <= n; L++){
        for(C = 1; C <= m; C++){
            sol += d[L][C] * 1LL * (n - L + 1) * (m - C + 1);
        }
    }
    fout<< sol <<"\n";
    return 0;
}