Cod sursa(job #250796)

Utilizator ciorile.chioareBogatu Adrian ciorile.chioare Data 31 ianuarie 2009 21:03:20
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include<stdio.h>

bool cmmdc(int x,int y)
{
	if( (x%2==0)&&(y%2==0) )
		return 0;
	if((x==y)&&(x!=1))
		return 0;
	while(y)
	{
		int p=y;
		y=x%y;
		x=p;
	}
	if(x==1)
		return 1;
	return 0;
}

int main()
{
	int n;
	int c=0;
	int i,j;
	
	freopen("fractii.in","r",stdin);
	freopen("fractii.out","w",stdout);

	scanf("%d",&n);
	
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(i==j)
				j++;
			if(cmmdc(i,j))
				c++;
		}
	}
	printf("%d",c);
	return 0;
}