Cod sursa(job #2271056)

Utilizator ClaudiuTClaudiu Timofte ClaudiuT Data 27 octombrie 2018 22:39:04
Problema Fractii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.19 kb
#include <bits/stdc++.h>

using namespace std ;

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

int My_CMMDC(int a, int b)
{
    if( a == b or a == 0 or b == 0 )
    {
        if(a > b)
            return a ;
        else
            return b ;
    }
    else
    {
        if(a % 2 == 0)
        {
            if(b % 2 == 0)
                return 2 * My_CMMDC(a / 2, b / 2) ;
            else
                return My_CMMDC(a / 2, b) ;
        }
        else
        {
            if(b % 2 == 0)
                return My_CMMDC(a, b / 2) ;
            else
            {
                if(a < b)
                    return My_CMMDC(a, (b - a) / 2) ;
                else
                    return My_CMMDC((a - b) / 2, b) ;
            }
        }
    }
}


int main()
{
    //ios_base::sync_with_stdio(false) ;
    //cin.tie(NULL) ;

    int n ;
    fin >> n ;

    int nr = 0 ;
    for(int i = 1 ; i <= n ; i += 1)
        for(int j = i ; j <= n ; j += 1)
        {
            if(i != j)
            {
                if(My_CMMDC(i , j) == 1)
                    nr += 2 ;
            }
        }
    fout << nr + 1 ;

    return 0 ;
}