Pagini recente » Cod sursa (job #2679594) | Cod sursa (job #3219447) | Cod sursa (job #1503620) | Cod sursa (job #2741627) | Cod sursa (job #10812)
Cod sursa(job #10812)
#include <stdio.h>
#include <math.h>
int cmmdc(long int a,long int b)
{
long int r;
int x=1;
if((a%b==0) || (b%a==0)) return 0;
while(x)
{
r=a%b;
a=b;
b=r;
if(r<2) x=0;
}
return r;
}
int main()
{
long int x,n,i,j;
FILE *fin;
FILE *fout;
fin=fopen("fractii.in","r");
fout=fopen("fractii.out","w");
fscanf(fin,"%d",&n);
fclose(fin);
x=0;
for(i=2;i<=n;i++)
if(i%2==0)
for(j=3;j<=i-1;j+=2)
x+=cmmdc(i,j);
else
for(j=2;j<=i-1;j++)
x+=cmmdc(i,j);
x+=n;
x=2*x;
x-=1;
fprintf(fout,"%d",x);
fclose(fout);
return 0;
}