Cod sursa(job #1049094)

Utilizator andreiiiiPopa Andrei andreiiii Data 6 decembrie 2013 21:17:27
Problema Dreptunghiuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>

using namespace std;

ifstream fin("dreptunghiuri.in");
ofstream fout("dreptunghiuri.out");

int cmmdc(int a, int b)
{
    int c;
    while(b)
    {
        c=a%b;
        a=b;
        b=c;
    }
    return a;
}

int main()
{
    int n, m, i, j, k, l;
    fin>>n>>m;
    long long sol=1LL*(n-1)*n*(m-1)*m/4;
    for(i=1;i<n;i++)
    {
        for(j=1;j<m;j++)
        {
            if(cmmdc(i, j)==1)
            {
                for(k=1;k*i<=n;k++)
                {
                    for(l=1;i*k+l*j<n&&j*k+i*l<m;l++)
                    {
                        sol+=1LL*(n-i*k-j*l)*(m-j*k-i*l);
                    }
                }
            }
        }
    }
    fout<<sol;
}