Pagini recente » Cod sursa (job #1210618) | Cod sursa (job #1569317) | Cod sursa (job #182895) | Cod sursa (job #734519) | Cod sursa (job #2220268)
#include <fstream>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
int cmmdc(int a,int b)
{
if(a!=b)
if(a>b)
return cmmdc(a-b,b);
else return cmmdc(a,b-a);
else
return a;
}
struct lista
{
int a,b;
}v[5000000];
int nr_tot;
bool check(int a,int b)
{
for(int i=1;i<=nr_tot;i++)
if(v[i].a==a and v[i].b==b)
return false;
return true;
}
int main()
{
int n;
fin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i!=j)
{
int ci=i,cj=j;
while(cmmdc(ci,cj)!=1)
{
int cmm=cmmdc(ci,cj);
ci/=cmm;
cj/=cmm;
}
if(check(ci,cj))
{
v[++nr_tot].a=ci;
v[nr_tot].b=cj;
}
}
fout<<nr_tot+1<<endl;
}