Cod sursa(job #916790)

Utilizator cruceruvladCruceru Vlad cruceruvlad Data 16 martie 2013 21:36:19
Problema Dreptunghiuri Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
# include<cstdio>
  
#define ok(x) ((x)%2==0 && (x)/2>=0 && (x)/2<w)
  
static int sqrt[405*405+5];
  
int calc (int b,int c,int w)
{
    int d=b*b-4*c;
    int ret=0;
    if(d==0){
        if(ok (b))
            ret++;
    } else if(d>0 && sqrt[d]){
        if(ok (b-sqrt[d]))
            ret++;
        if(ok (b+sqrt[d]))
            ret++;
    }
  
    return ret;
}
  
int main (void)
    {
    freopen ("dreptunghiuri.in","r",stdin);
    #ifdef INFOARENA
    freopen ("dreptunghiuri.out","w",stdout);
    #endif
  
    for(int i=1;i<=405;i++)
        sqrt[i*i]=i;
      
    int m,n;
    long long ret=0;
    scanf ("%d%d",&m,&n);
    for(int w=1;w<m;w++)
        for(int h=1;h<n;h++)
            for(int a=0;a<h;a++)
                ret+=calc (w,a*(h-a),w)*(m-w)*(n-h);
  
    printf ("%d",ret);
    return 0;
}