Created
September 24, 2012 15:01
-
-
Save Yi-Tseng/3776400 to your computer and use it in GitHub Desktop.
This file contains 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> | |
#define swap(x,y) int t=x;x=y;y=t; | |
typedef unsigned long long ull; | |
ull foo(int a,int b){ | |
ull cycle; | |
ull c,n; | |
ull max = 0; | |
if(a>b){ | |
swap(a,b) | |
} | |
for(c=a;c<=b;c++){ | |
cycle = 1; | |
n = c; | |
while(n!=1){ | |
n = n%2==1?3*n+1 : n/2; | |
cycle ++; | |
} | |
if(cycle>max){ | |
max = cycle; | |
} | |
} | |
return max; | |
} | |
int main(int argc, const char * argv[]) | |
{ | |
int a,b; | |
while(scanf("%d%d",&a,&b)!=EOF){ | |
printf("%d %d %llu\n",a,b,foo(a, b)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment