Cod sursa(job #2293186)

Utilizator RaduXD1Nicolae Radu RaduXD1 Data 30 noiembrie 2018 17:23:40
Problema Dreptunghiuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#include<fstream>
#include<cstring>
using namespace std;
ifstream fin("dreptunghiuri.in");
ofstream fout("dreptunghiuri.out");
int i,f[170001],n,m,h,w,a,delta,sol,aux,c1,c2;
long long ss;

int main()
{
    for(i=1;i<=400;i++)
        f[i*i]=i;
    fin>>m>>n;
    for(h=2;h<=n;h++)
        for(w=2;w<=m;w++)
        {
            sol=1;w--;h--;
            for(a=1;a<h;a++)
            {
                delta=w*w-4*a*(h-a);aux=f[delta];
                if(delta==0&&w%2==0) sol++; if(aux==0) continue;
                c1=(w-aux)/2;c2=(w+aux)/2;
                if(!((w-aux)%2)&&c1>0&&c1<w) sol++;
                if(!((w+aux)%2)&&c2>0&&c2<w) sol++;
            }
            w++;h++;
            ss+=1LL*sol*(n-h+1)*(m-w+1);
        }
    fout<<ss;
    return 0;
}