Skip to content

Instantly share code, notes, and snippets.

@amoshyc
Created November 2, 2014 12:23
Show Gist options
  • Save amoshyc/fcd16d4f835c82bc058e to your computer and use it in GitHub Desktop.
Save amoshyc/fcd16d4f835c82bc058e to your computer and use it in GitHub Desktop.
uva100.c
#include <stdio.h>
#include <stdlib.h>
int max(const int a, const int b) {
return ((a > b) ? a : b);
}
int min(const int a, const int b) {
return ((a < b) ? a : b);
}
int get_length(long long n) {
int cnt = 1;
while (n != 1) {
cnt++;
if (n % 2 == 0)
n = n / 2;
else
n = 3 * n + 1;
}
return cnt;
}
int main() {
int a, b;
while (scanf("%d %d", &a, &b) != EOF) {
int max_length = -1;
int i;
for (i=min(a, b); i <= max(a, b); i++)
max_length = max(max_length, get_length(i));
printf("%d %d %d\n", a, b, max_length);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment