Cod sursa(job #934508)

Utilizator PsychoRoAlex Buicescu PsychoRo Data 30 martie 2013 19:14:10
Problema Fractii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <iostream>
#include <fstream>

std::ifstream fin("fractii.in");
std::ofstream fout("fractii.out");
//std::ifstream fin("date.in");
//std::ofstream fout("date.out");

long cmmdc(long a, long b)
{
	if(!b)
	{
		return a;
	}
	else
	{
		return cmmdc(b, a%b);
	}
}

void citeste()
{
	long n = 0;
	fin>>n;
	long nr = 0;

	for(long i = 2 ; i <= n ; i++)
	{
		long minim = 1;
		for(long j = 2; j <= n ; j+=minim)
		{
			if(cmmdc(i, j) != 1)
			{
				if(minim == 1)
				{
					minim = cmmdc(i, j);
				}
				nr++;
//				std::cout<<i<<" "<<j<<"; "<<nr<<'\n';
			}
		}
	}
	//nr = nr * 2 - 1;
	nr = n*n - nr;
//	std::cout<<'\n';
//	std::cout<<nr<<'\n';
	fout<<nr;
}

int main()
{
	citeste();
	return 0;
}