All pastes #986824 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-04-16 00:39 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>


int CalcStep(int n){
   int step = 1;
	while (n>1) {
		if (n % 2 == 0) {
			n = n/2;
			step++;
		}
		else {
			n = 3*n+1;
			step++;
		}
	}
	return step;
}

int main(){
	int a;
	int b;
	int greaterstep;
	int temp;
	while (scanf("%d %d", &a, &b) != EOF) {
	if (a>b) {
    temp=a;
    a=b;
    b=temp; 
    }
	greaterstep = CalcStep(a);
	for (int x=1; x<=b; x++) {
        int xuxu = CalcStep(a+x);
		if (greaterstep<xuxu) {
			greaterstep = xuxu;
		}
	}
    if (temp) {
       printf("%d %d %d", b, a, greaterstep);
    }  
    else {
       printf("%d %d %d", a, b, greaterstep);
    }          
}
}