Created
October 26, 2014 18:06
-
-
Save henrybear327/5d9a5e0ef74887afc916 to your computer and use it in GitHub Desktop.
ACM100(黃鈺程神ans).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