Cod sursa(job #1759262)

Utilizator mesbotMeszaros Botond mesbot Data 18 septembrie 2016 18:57:56
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>
#include <fstream>

using namespace std;

void work(int a, int b, int &p)
{
    while(a!=b)
        {
            if(a>b) a -= b;
            else b -= a;
        }
    if(a == 1) p++;
}

int main()
{
    ifstream f("fractii.in");
    ofstream g("fractii.out");


    int n;

    f>>n;

    int p = 2*n-1;

    for(int i = 2; i <= n; i++)
        {
            for(int j = 2; j <= n; j++)
                {
                    work(i,j, p);
                }
        }

    g<<p;

    return 0;
}