Skip to content

Instantly share code, notes, and snippets.

@Yi-Tseng
Created September 24, 2012 15:01
Show Gist options
  • Save Yi-Tseng/3776400 to your computer and use it in GitHub Desktop.
Save Yi-Tseng/3776400 to your computer and use it in GitHub Desktop.
#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