Cod sursa(job #612972)

Utilizator GheorghePPisarenco Gheorghe GheorgheP Data 14 septembrie 2011 01:34:48
Problema Fractii Scor 0
Compilator cpp Status done
Runda test_info20 Marime 0.65 kb
// fractii.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream.h>
#include "fstream.h"

int reduct(int x, int y)
{
	int c, z=0;
	if (x>y)
		c=y;
	else c=x;

	for(int i=c; i>1; i--)
	{
		if((x%i==0)&&(y%i==0))
			break;
		if (i==2) 
			z=1;
	}
	return z;
}
int main()
{
	ifstream input;
	ofstream output;

	input.open("input.in");
	output.open("output.out");
	
	int n;

	input >> n;
	int s=(n*2)-1;

	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
		{
			if((i%j==0)||(j%i==0))
			{}
			else if(i==j)
			{}
			else s=s+reduct(i,j);
		}
	output << s;

	return 0;
}