Cod sursa(job #27365)

Utilizator codertuxNistor Andrei codertux Data 6 martie 2007 12:55:12
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.84 kb
/***************************************************************************
 *   Copyright (C) 2007 by Nistor Andrei   *
 *   [email protected]   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <fstream>
#include <iostream>

using namespace std;

long int N, k=0;

void citire(){
	fstream in ( "fractii.in", ios::in );

	in>>N;

	in.close();
}

void tipar(){
	fstream out("fractii.out", ios::out);

	out<<k;
	out.close();
}

int cmmdc(long int a, long int b){
	int r;
	do{
		r=a%b;
		a=b;
		b=r;
	}while(r);
	return a==1;
}

int main ( int argc, char *argv[] )
{
	citire();
	long int i,j;
	for (i=1; i<=N; ++i)
		for(j=1; j<=N; ++j)
			if (cmmdc(i, j))
				++k;
	tipar();
	return 0;
}