fork download
  1. #include <stdio.h>
  2. int collatz(int a1, int *amax)
  3. {
  4. while (a1 != 1) {
  5. if (*amax < a1)*amax = a1;
  6. a1 = (a1 % 2) ?
  7. a1 * 3 + 1 :
  8. a1 / 2;
  9. return 1 + collatz(a1, amax);
  10. }
  11. return 1;
  12. }
  13. int main()
  14. {
  15. int i, amax, len;
  16. int max_of_i, max_of_amax = 0, max_of_len = 0;
  17. for (i = 2; i <= 100000; ++i) {
  18. amax = 0;
  19. len = collatz(i, &amax);
  20. if (max_of_amax < amax) {
  21. max_of_i = i;
  22. max_of_amax = amax;
  23. max_of_len = len;
  24. }
  25. // printf("%d %d %d\n", i, len, amax);
  26. }
  27. printf("%d %d %d\n", max_of_i, max_of_len, max_of_amax);
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0.05s 2292KB
stdin
Standard input is empty
stdout
77671 232 1570824736