Cod sursa(job #885452)

Utilizator desoComan Andrei deso Data 21 februarie 2013 23:38:40
Problema Dreptunghiuri Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <vector>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <string>
using namespace std;

#define INFILE "dreptunghiuri.in" 
#define OUTFILE "dreptunghiuri.out"

ifstream fin(INFILE);
ofstream fout(OUTFILE);

int main() {
   long long n, m;
   fin >> n >> m;
   if( m==1 || n==1 ) {
      fout << '0';
      return 0;
   }

   if( n>m ) swap(n, m);
   
   m--; n--;
   long long res = m * (m+1) * n * (n+1) / 4;
   //fout << res << endl;

   for(int b=1; b<m; b++)
   for(int a=1; a<n; a++)
   for(int xa=1; a+xa<=n; xa++)
      if( (a*xa) % b == 0 )
      {
         int xb = a*xa/b;
         int y = xb+b;
         if( a+xa<=n && xb<=m && y<=m )
            res += (n-xa-a+1) * (m-y+1);
      }

   fout << res;

   return 0;
}