Cod sursa(job #443950)

Utilizator danvlnDan Vln danvln Data 18 aprilie 2010 22:44:30
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <iostream>
#include <fstream>
using namespace std;


int cmmdc(long a, long b)
{
	if(b==0 || a==0)
		return 0;

	long c;
	while(b)
	{
		c = a%b;
		a = b;
		b = c;
	}

	return a==1?0:a;
}

int main()
{
	int n;

	ifstream fin("fractii.in");
	ofstream fout("fractii.out",ios::out);

	fin>>n;
	
	int count=0;

    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(j%i != 0 &&  i%j !=0)
            {
                if(cmmdc(i,j) ==0)
                {
                    count ++;
                    cout<<i<<"/"<<j<<"    ";
                }
            }
        }
        cout<<endl;
    }
	count += n + (n-1) /*because I use the trick with %*/;
	cout<<count;

	fout<<count;

	fin.close();
	fout.close();

	return 0;
}