Pagini recente » Cod sursa (job #2904178) | Cod sursa (job #706790) | Cod sursa (job #1187926) | Cod sursa (job #1556749) | Cod sursa (job #357569)
Cod sursa(job #357569)
Utilizator |
Marian S eu93 |
Data |
19 octombrie 2009 20:01:32 |
Problema |
Fractii |
Scor |
0 |
Compilator |
cpp |
Status |
done |
Runda |
CNRV #3 |
Marime |
0.44 kb |
#include <fstream.h>
#include <math.h>
int main()
{ long n,i,j,k=1,ok,l,max;
ifstream f("fractii.in");
ofstream g("fractii.out");
f>>n; k=n;
for (i=2;i<=n;i++)
for (j=1;j<=n;j++){
if (i!=j) {ok=1;
if (i%2==0 && j%2==0) ok=0;
if (ok==1) {
if (i>j) max=i;
else max=j;
for (l=3;l<=sqrt(max) && ok==1;l+=2) if (i%l==0 && j%l==0) ok=0;
}
if (ok==1) k++;
}
}
g<<k;
f.close();
g.close();
return 0;
}