Pagini recente » Cod sursa (job #1746633) | Cod sursa (job #1296237) | Cod sursa (job #2015512) | Profil Ionescu_Miruna | Cod sursa (job #1245596)
#include <stdio.h>
int lnko(int x, int y) {
while (x!=y)
if (x>y) x-=y;
else y-=x;
return x;
}
int main() {
int n,i,j,s=0;
FILE *f;
f=fopen("fractii.in","r");
fscanf(f,"%d",&n);
fclose(f);
for (i=1; i<=n; i++)
for (j=1; j<i; j++)
if (lnko(i,j)>=2) ++s;
s=s*2+n-1;
f=fopen("fractii.out","w");
fprintf(f,"%d",n*n-s);
fclose(f);
return 0;
}
/*
int lnko(int x, int y) {
while (x!=y)
if (x>y) x-=y;
else y-=x;
return x;
}
int main() {
struct tort {
int sz,n;
}t[10000];
int n,m=0,i,j,k,u,b;
FILE *f;
f=fopen("fractii.in","r");
fscanf(f,"%d",&n);
fclose(f);
for (i=1; i<=n; i++)
for (j=1; j<=n; j++) {
k=lnko(i,j); b=0;
for (u=0; u<m; u++)
if ((t[u].sz== (int) i/k) && (t[u].n== (int) j/k)) b=1;
if (b==0) { t[m].sz=i/k; t[m].n=j/k; ++m; }
}
f=fopen("fractii.out","w");
fprintf(f,"%d",m);
fclose(f);
return 0;
}
*/