Pagini recente » Cod sursa (job #2770001) | Cod sursa (job #1632931) | Cod sursa (job #277379) | Cod sursa (job #700758) | Cod sursa (job #214228)
Cod sursa(job #214228)
#include<fstream.h>
void back(long k);
int ok(long k);
long n,x[3],l=0;
int cmmdc(long a,long b);
int main()
{
ifstream fin("fractii.in");
ofstream fout("fractii.out");
fin>>n;
back(1);
fout<<l+1;
fin.close();
return 0;
}
void back(long k)
{
for (long i=1;i<=n;i++)
{
x[k]=i;
if (ok(k))
if (k==2)
l++;
else
back(k+1);
}
}
int ok(long k)
{
if (k==1) return 1;
if (x[2]==x[1]) return 0;
if (k==2)
if (cmmdc(x[k],x[k-1])!=1)
return 0;
return 1;
}
int cmmdc(long a,long b)
{
if (a==1)
return 1;
if (b==1)
return 1;
while (a!=b)
{
if (a>b)
a=a-b;
else
b=b-a;
}
return a;
}