Cod sursa(job #907990)

Utilizator veleanduAlex Velea veleandu Data 8 martie 2013 16:40:11
Problema Dreptunghiuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include<cstdio>
#include<iostream>
using namespace std;

int gcd( int a,int b ){
    if(!b) return a;
    return gcd( b, a%b );
}

int n,m,a,b,i,j;
long long rez;

int main(){
    freopen("dreptunghiuri.in","r",stdin);
    freopen("dreptunghiuri.out","w",stdout);
    cin>>n>>m;
    for( a=1; a<n; ++a ){
        for( b=0; b<m; ++b ){
            for( i=1; i*a<n; ++i ){
                for( j=1; i*a+b*j<n && i*b+j*a<m; ++j ){
                    if( gcd(i,j) == 1 ){
                        rez=rez+1LL*(n-(i*a+b*j))*(m-(b*i+a*j));
                    }
                }
            }
        }
    }
    cout<<rez<<"\n";
    return 0;
}