1.

package sem2.am.thecollatzsequence;

/**
* Angewandte Mathematik, SS11
* Problem: 694 - The Collatz Sequence
* Link: http://uva.onlinejudge.org/external/6/694.pdf
*
* @author Florian Stein
* @author Franz Sommer
* @version 1.0, 05/08/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 1.224
*/

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
int currentCase = 0;

// schleife faelle
while (sc.hasNext()) {

currentCase++;
int terms = 1;
long a = sc.nextInt();
int originalA = (int) a;
int limit = sc.nextInt();

// abbruch bei negativen zahlen
if ((a < 0 && limit < 0)) {
break;
}

// step-schleife
while (a != 1) {
if (a % 2 == 0) {
a = a / 2;
} else {
a = 3 * a + 1;
}
// abbruch wenn limit ueberschritten
if (a > limit) {
break;
}
terms++;
}

// ausgabe
System.out.println("Case " + currentCase + ": A = " + originalA
+ ", limit = " + limit + ", number of terms = " + terms);
}
}

}
-----------------------


1.


/**
* FWP: Ausgewaehlte Probleme aus dem ACM (SS10)
*
* Method: ad hoc
* Problem: 694 - The Collatz Sequence
* Accepted: 1.784
* @author Evgeni Pavlidis
*
*/


import java.io.*;
import java.util.*;

class Main {

public static void main(String...args)
{
Scanner scanner = new Scanner(System.in);
long a, limit, c, i;
int caseNumber = 1;

while(true)
{
i = a = scanner.nextInt();
limit = scanner.nextInt();
if(a < 0 && limit < 0)
break;

c = 0;
while(a > 1 && a <= limit)
{
c++;
if(a % 2 == 0)
a /= 2;
else
a = a*3 + 1;
}

if(a == 1)
c++;

System.out.printf("Case %d: A = %d, limit = %d, number of terms = %d\n", caseNumber++, i, limit, c);
}
}
}