Cod sursa(job #741614)

Utilizator florea.fmfFlorea Marius Florin florea.fmf Data 26 aprilie 2012 16:33:55
Problema Fractii Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.72 kb
program ia;

var
	i,j,n,k:longint;
	fIn,fOut:text;
	
function common_divisor(x,y:integer):boolean;
	var
		b,i,j:integer;
		a:array of integer;
	begin
		common_divisor:=false; j:=0;
		if (x>=y) then
			b:=x
		else
			b:=y;
		
		setLength(a,b);
		
		for i:=2 to x do
			if (x mod i=0) then begin
				j:=j+1; a[j]:=i;
			end;
			
		for i:=1 to j do
			if (y mod a[i]=0) then begin
				common_divisor:=true;
				break;
			end;
	end;	
	
begin
	assign(fIn,'fractii.in'); reset(fIn);
	assign(fOut,'fractii.out'); rewrite(fOut);
	readln(fIn,n);
	
	k:=0;
	for i:=1 to n do
		for j:=1 to n do
			if (i mod j<>0) and (common_divisor(i,j)=false) then
				k:=k+1
			else if (j=1) then
				k:=k+1;

	writeln(fOut,k);
	
	close(fIn); close(fOut);
end.