Cod sursa(job #3273054)

Utilizator DobrePetruDobre Petru Daniel DobrePetru Data 1 februarie 2025 09:25:08
Problema Fractii Scor 10
Compilator cpp-64 Status done
Runda cex_8 Marime 0.77 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 <bits/stdc++.h>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
int n,rez;
int cmmdc(int a,int b)
{
    int r=a%b;
    while(r)
    {
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int main()
{
    fin>>n;
    rez=n;
    for(int i=2; i<=n; i++)
    {
      for(int j=1; j<=n; j++) if(cmmdc(i,j)==1) rez++;
    }
  fout<<rez;
    return 0;
}