Cod sursa(job #2101628)

Utilizator i.uniodCaramida Iustina-Andreea i.uniod Data 7 ianuarie 2018 19:03:54
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
int n;
long long int nr;

bool cmmdc(int x, int y)
{
    int z;
    if(x<y)
        swap(x,y);
    while(x%y)
    {
        z=x%y;
        x=y;
        y=z;
    }
    if(y==1)
        return true;
    return false;
}

int main()
{
    fin>>n;
    nr=n;
    for(int i=2; i<=n; ++i)
        for(int j=1; j<=n; ++j)
            if(cmmdc(i,j))
                nr++;
    fout<<nr<<'\n';
    return 0;
}