Cod sursa(job #2428267)

Utilizator ageneohasMart Florin ageneohas Data 4 iunie 2019 15:17:48
Problema Fractii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<fstream>

using namespace std;
bool function(int a,int b)
{
    while(a!=b)
    {
        if(a>b)
        {
            a=a-b;
        }
        else
        {
            b=b-a;
        }
    }
    if(a==1)
        return 1;
    return 0;
}
int main()
{
    int n;
    ifstream f("fractii.in");
    ofstream g("fractii.out");
    f>>n;
    unsigned int numere=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        if(function(j,i))
            numere++;
    }
    g<<numere<<endl;
    f.close();
    g.close();
    return 0;
}