ACM (UVa) : 371


// http://uva.onlinejudge.org/external/3/371.html

#include <stdio.h>

int main ()
{
	long int F, S, I, Count, Value, Max, J;

	while (scanf("%ld %ld", &F, &S)){

		if (F==0 && S==0)
			break;

		if (F>S){
		    F ^= S;
		    S ^= F;
		    F ^= S;
		}

		Max = 0;

		for (I=F; I<=S; I++){
			Count = 0;
			J = I;

			do {
				if (J%2==0)
					J/=2;
				else
					(J*=3)++;
				Count++;
			} while (J!=1);

			if (Count > Max){
				Value = I;
				Max = Count;
			}

		}
		printf("Between %ld and %ld, %ld generates the longest sequence of %ld values.\n", F, S, Value, Max);
	}
	return 0;
}

One thought on “ACM (UVa) : 371

  1. 55 5
    Between 5 and 55, 54 generates the longest sequence of 112 values.
    666 666
    Between 666 and 666, 666 generates the longest sequence of 113 values.
    663 128
    Between 128 and 663, 649 generates the longest sequence of 144 values.
    0 0
    Press any key to continue.
    
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s