Cod sursa(job #914784)

Utilizator S7012MYPetru Trimbitas S7012MY Data 14 martie 2013 13:59:07
Problema Dreptunghiuri Scor 90
Compilator cpp Status done
Runda Lista lui wefgef Marime 0.73 kb
#include <iostream>
#include <fstream>
using namespace std;

int w,h,sq[1000005],n,m;
long long rez;

int check(int x,int b) {
  return (x%2==0 && x>=0 && x/2<b);
}

int calc(int b, int c) {
  int d=b*b-4*c;
  if(d==0) return check(b,b);
  else if(d>0 && sq[d])
    return check(b-sq[d],b)+check(b+sq[d],b);
  return 0;

}

long long nsol(int x) {
  return calc(w,x*(h-x))*1LL*(n-w)*(m-h);
}

int main()
{
    ifstream f("dreptunghiuri.in");
    ofstream g("dreptunghiuri.out");
    f>>n>>m;
    for(int i=1; i<=500; ++i) sq[i*i]=i;
    for(w=1; w<n; ++w) for(h=1; h<m; ++h) {
      for(int a=0; a<=h/2; ++a) rez+=nsol(a)*2;
      if(h%2==0) rez-=nsol(h/2);
      rez-=nsol(h);
    }
    g<<rez;
    return 0;
}