Pagini recente » Divseq | Cod sursa (job #2818460) | Cod sursa (job #2690469) | Cod sursa (job #173471) | Cod sursa (job #357274)
Cod sursa(job #357274)
#include <fstream>
#include <iostream>
using namespace std;
int fi,fo,n,p,q,fcount;
int prime (int,int);
int main ()
{
fstream fi("fractii.in",ios::in);
fi>>n;
fi.close();
for (p=2; p<=n; p++)
for (q=2; q<=n; q++)
{
//cout<<p<<"/"<<q<<"-"<<prime(p,q)<<endl;
if (prime(p,q)==0) fcount++;
}
fcount+=n*2-1;
fstream fo("fractii.out",ios::out);
fo<<fcount;
fo.close();
//cout<<fcount;
return 0;
}
int prime (int a,int b)
{
if ((a%b)==0 && b!=1) return 1;
else
{
int i,minim,gasit;
gasit=0;
if (a>b) minim=b;
else minim=a;
i=2;
while (i<=minim && gasit==0)
{
if ((a%i)==0 && (b%i)==0) gasit=1;
i++;
}
return gasit;
}
}