Advertisement
Guest User

Untitled

a guest
Oct 13th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. //
  2. // main.c
  3. // 3n_plus_1
  4. //
  5. // Created by Vincent Liu on 2017/10/13.
  6. // Copyright © 2017年 Vincent Liu. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10.  
  11. int main(int argc, const char * argv[]) {
  12. int start, end, i, step, input, max, a, b;
  13.  
  14. while(scanf("%d %d", &a, &b) != EOF) {
  15. max = 0;
  16. if (a <= b) {
  17. start = a;
  18. end = b;
  19. }
  20. else {
  21. end = a;
  22. start = b;
  23. }
  24. for(i = start; i <= end; i++) {
  25. input = i;
  26. step = 1;
  27. while(input != 1) {
  28. if(input % 2 == 0) {
  29. input = input / 2;
  30. }
  31. else {
  32. input = input * 3 + 1;
  33. }
  34. step++;
  35. }
  36. if(step > max){
  37. max = step;
  38. }
  39. }
  40. printf("%d %d %d\n", a, b, max);
  41. }
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement