All pastes #898582 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-02-10 13:11 UTC
rendered paste body
#include <iostream>
#include <vector>

#define ALL(a) (a).begin(),(a).end()

using namespace std;

int main()
{
	int i, j;
	vector <int> ii, jj;
	
	while(cin>>i>>j)
	{
		ii.push_back(i);
		jj.push_back(j);
	}
	
	int limit = max(*max_element(ALL(ii)), *max_element(ALL(jj)));
	
	vector <bool> mem(1000001, false);
	int cycle;
	
	mem[1] = 1;
	mem[2] = 2;
	for(int kk = 3; kk <= limit; kk++)
	{
		cycle = 0;
		int k = kk;
		bool done = false;
		while(!done)
		{
			cycle++;
			if(k % 2 == 0)
			{
				k/=2;
				if(mem[k] != 0)
				{
					mem[kk] = mem[k]+cycle; 
					//cout<<"cycle len of"<<kk<<" = "<<mem[kk]<<endl;
					done = true;
				}
			}
			else
				k = 3*k+1;
		}
	}
	
	for(int k = 0; k < ii.size(); k++)
	{
		cout<<ii[k]<<" "<<jj[k]<<" "<<( *max_element(mem.begin()+ii[k], mem.begin()+jj[k]+1) )<<endl;
	}
	
	return 0;
}