Cod sursa(job #1132759)

Utilizator acesniperPetre Popescu acesniper Data 3 martie 2014 21:33:19
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.41 kb
#include<stdio.h>

int cmmdc(int x, int y){
	int z;
	while(y){
		z = x % y;
		x = y;
		y = z;
	}
	return x;
}

int main(){
	FILE *f = fopen("fractii.in", "r");
	FILE *g = fopen("fractii.out", "w");
	int n, nr=0;
	fscanf(f, "%d", &n);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(cmmdc(i,j) == 1){
				nr++;
			}
		}
	}
	fprintf(g, "%d", nr);
	fclose(f);
	fclose(g);
	return 0;
}