Created
November 2, 2014 12:23
-
-
Save amoshyc/fcd16d4f835c82bc058e to your computer and use it in GitHub Desktop.
uva100.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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