Cod sursa(job #642242)

Utilizator penultim_oVijiala Tudor Gabriel penultim_o Data 30 noiembrie 2011 19:15:29
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream>
using namespace std;
#define L long long

L div(L a, L b)
{
    L t;
    while(b)
    {
        t = b;
        b = a%b;
        a = t;
    }
    return a;
}

int main()
{
    int n,p,q,s=0;
    ifstream in("fractii.in");
    ofstream out("fractii.out");
    in >> n;
    in.close();
    if(n<1){out.close(); return 0;}
    s+=2*n-1;
    for(p=2;p<n;p++)
        for(q=p+1;q<=n;q++)
            if(div(p,q) == 1)
                s+=2;
    out << s;
    out.close();
    return 0;
}