SMASIF

100 - 3n+1

Dec 15th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int a,b,i,k,j,c,sum;
  5. while(scanf("%d %d",&a,&b)==2)
  6. {
  7. sum=0;
  8. printf("%d %d",a,b);
  9. if(a>b)
  10. {
  11. k=b;
  12. b=a;
  13. a=k;
  14. }
  15. for(i=a; i<=b; i++)
  16. {
  17. c=1;
  18. j=i;
  19. while(j > 1)
  20. {
  21. if(j % 2==0)
  22. j = j/2;
  23. else
  24. j = (3*j)+1;
  25. c++;
  26. }
  27. if(c>=sum)
  28. sum=c;
  29. }
  30. printf(" %d\n",sum);
  31. }
  32. return 0;
  33. }
Add Comment
Please, Sign In to add comment