Cod sursa(job #2850528)

Utilizator MTAxD12Preda Andrei MTAxD12 Data 16 februarie 2022 21:47:00
Problema Fractii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include<fstream>
using namespace std;

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

bool cmmdc(int i, int j)
{
    while(i != j)
    {
        if(i > j)
        {
            i -= j;
        }
        else
        {
            j -= i;
        }
    }

    if(i != 1) return true;
    else       return false;
}

int main()
{
    int n, s = 0;
    fin>>n;

    if(n == 1)
    {
        fout<<s + 1;
        return 0;
    }

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
        {
            if(!cmmdc(i, j))
            s++;
        }


    fout<<s;

    fin.close();
    fout.close();
}