Cod sursa(job #525670)

Utilizator Antonius74Antonius Cezar Hegyes Antonius74 Data 25 ianuarie 2011 20:21:05
Problema Fractii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <cstdio>
#include <vector>
using namespace std;
int main()
{
	
	int n,anz=1,anf=1,x,i,j,p,aux=1;
	bool fertig=false;
	vector <int> bruche (3);
	bruche[1]=1;
	bruche[2]=1;
	
	scanf ("%d",&n);
	
	while (fertig==false)
	{
		x=bruche.size();
		p=0;
		for (int t=anf;t<x;t+=2)
		{
			i=bruche[t];
			j=bruche[t+1];
			if ((i+j)<=n)
				anz+=2;
			else
				p+=2;
			bruche.push_back(i+j);
			bruche.push_back(j);
			bruche.push_back(i);
			bruche.push_back(i+j);
		}
		aux*=2;
		if (p==aux)
			fertig=true;
		anf=anf*2+1;
	}

	for (int q=1;q<bruche.size();q+=2)
		printf ("%d / %d \n",bruche[q],bruche[q+1]);
	
	printf ("%d", anz);
	
	return 0;
}