Pagini recente » Cod sursa (job #3142650) | Cod sursa (job #2651073) | Cod sursa (job #2602061) | Cod sursa (job #2456577) | Cod sursa (job #2188710)
#include <iostream>
#include <fstream>
#define lim 1000000
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
int n;
bool Ireductibil(int a, int b)
{
//verificam daca a/b e ireductibil;
int r=0;
while(b!=0)
{
r=a%b;
a=b;
b=r;
}
if(a==1)
return true;
else return false;
}
int fr=0, V[lim];
void Back(int A)
{ V[A]=1;
while(V[A]<n+1)
{
if(Ireductibil(A,V[A]))
fr++;
V[A]=V[A]+1;
}
if(A<n)
Back(A+1);
}
int main()
{
fin>>n;
Back(1);
fout<<fr;
return 0;
}