1.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS09
* Problem: 694 - Collatz Series
* Link: http://uva.onlinejudge.org/external/6/694.pdf
*
* @author Felix Dietrich
* @version 1.0, 01/15/2010
*
* Method : Bruteforce
* Status : Accepted
* Runtime: 1.192
*/
import java.util.Locale;
import java.util.Scanner;

public class Main
{
public static void main(String... s)
{
Scanner sc = new Scanner(System.in);
sc.useLocale(Locale.ENGLISH);

int a,l;
int cases = 1;

while(sc.hasNext())
{
a = sc.nextInt();
l = sc.nextInt();

if(a < 0 && l < 0)
return;

System.out.println(String.format("Case %d: A = %d, limit = %d, number of terms = %d",cases,a,l,collatz(a,l)));

cases++;
}
}

private static int collatz(int a, int l)
{
int counter = 1;
while(a <= l && a > 0)
{
if(a == 1)
{
return counter;
}
if((a&1)==0)
{
a >>= 1;
}
else
{
a = 3*a+1;
}
counter++;
}
//System.out.println("limit reached");
return counter-1;
}
}