Cod sursa(job #444357)

Utilizator danvlnDan Vln danvln Data 20 aprilie 2010 07:54:34
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 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++)
        {
            // both odd
            if( (i & 0x1) == 0 && 
                (j & 0x1) == 0)
            {
                continue;
            }
            
            if(j%i != 0 &&  i%j !=0)
            {
                if(cmmdc(i,j) ==0)
                {
                    count ++;
                    cout<<i<<"/"<<j<<"    ";
                }
            }
        }
        cout<<endl;
    }

	count += n + (n-1);
	
	cout<<count;

	fout<<count;

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

	return 0;
}