1. C, Evgeni Pavlidis


/**
* ACM programming Contest WS 08/09
* UVa Status: accepted
* Run Time: 0.170
* @author Evgeni Pavlidis evgenipavlidis@yahoo.de
*/
#include <stdio.h>

int main()
{
int start, end;
int i,j;

while(1)
{
scanf("%d %d\n", &start, &end);
if(start == 0 && end == 0)
return 0;

if(start > end)
{
int tmp = start;
start = end;
end = tmp;
}

int maxNumber, maxValue = -1;
int value;

for(i = start; i <= end; i++)
{
value = ackermann(i);
if(value > maxValue)
{
maxValue = value;
maxNumber = i;
}
}

printf("Between %d and %d, %d generates the longest sequence of %d values.\n", start, end, maxNumber, maxValue);



}
}

int ackermann(int n)
{
int counter = 0;

do
{
counter++;
if(n % 2 == 0)
n /= 2;
else
n = 3*n +1;
}while(n > 1);

return counter;
}

2. C, Tobias Fuchs

/* Author: Tobias Fuchs
* Problem: 371
* Verdict: Accepted
* Runtime: 0.170
*/

#include <stdio.h>

void swap(int * a, int * b)
{
int tmp = *a;
*a = *b;
*b = tmp;
}

int ackermann_rounds(int n)
{
int val = 0;
do {
val++;
if(n % 2 == 0) { n /= 2; }
else { n = 3 * n + 1; }
} while (n > 1);
return val;
}

int main()
{
int start, end, value, i, max, limit;

while(1) {
scanf("%d %d", &start, &end);
if(start == 0 && end == 0) { return 0; }
if(start > end) { swap(&start,&end); }

max = -1;
for(i = start; i <= end; i++)
{
value = ackermann_rounds(i);
if(value > max) {
max = value;
limit = i;
}
}
printf("Between %d and %d, %d generates the longest sequence of %d values.\n", start, end, limit, max);
}
}

3. Java, Evgeni Pavlidis


/* ??????
*/


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

class Main extends Thread {

private int saveMax = -1;
private int saveMaxNumber;
private Scanner input = new Scanner(System.in);

public static void main(String... args)
{
(new Main()).start();
}

public void run()
{
while(true)
calculate(input.useDelimiter("\n").next());
}

void calculate(String s)
{
saveMax = -1;
Scanner scanner = new Scanner(s);
int start = scanner.nextInt();
int end = scanner.nextInt();
if(start > end)
{
int tmp = end;
end = start;
start = tmp;
}

if(start == 0 && end == 0)
System.exit(0);

calcMax(start, end);

System.out.printf("Between %d and %d, %d generates the longest sequence of %d values.\n",
start, end, saveMaxNumber, saveMax);
}

void calcMax(int start, int end)
{

for(int i = start; i <= end; i++)
{
int result = ackermann(i);
if(result > saveMax)
{
saveMax = result;
saveMaxNumber = i;
}
}
}

int ackermann(int n)
{
int counter = 0;
while(n > 1)
{
if(n%2 == 0)
n = n/2;
else
n = 3*n + 1;
counter++;
}
return counter;
}

}