Cod sursa(job #1355310)

Utilizator ajeccAjechiloae Eugen ajecc Data 22 februarie 2015 16:29:12
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>
#include <iostream>
#define tip unsigned long long
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
tip n;
tip sol(tip p); tip aux(tip l); tip cmmdc(tip a, tip b);
int main()
{
    fin>>n;
    fout<<sol(n);
    fin.close(); fout.close(); return 0;
}

tip cmmdc(tip a, tip b)
{
    while(a!=b)
    {
        if(a>b) a-=b; else if(a<b) b-=a;
    }
    return a;
}


tip aux(tip l)
{
    tip sc=0;
    for(tip i=2; i<=l; i++)
        if(cmmdc(l, i)!=1) sc++;
    return sc;
}

tip sol(tip p)
{
    if(p==1) return 1;
    else
    {
        return sol(p-1)+2*(p-aux(p));
    }
}

//rezolvare cu recursivitate;