fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. unsigned long long f(unsigned long long x){
  5. if (x%2==0)
  6. return x/2;
  7. else
  8. return 3*x+1;
  9. }
  10.  
  11. int main(){
  12. unsigned int i, j, sum, *ii, cnt, k, l, m;
  13. unsigned long long temp, *jj;
  14. while (scanf("%lu%lu",&i,&j)!=EOF)
  15. {
  16. m=1;
  17. cnt=i;
  18. sum=0;
  19. ii=(unsigned int*)calloc(j-i+1, sizeof(unsigned int));
  20. for (temp=(unsigned long long)cnt;cnt<=j;cnt++)
  21. {
  22. temp=(unsigned long long)cnt;
  23. if (ii[cnt-i]!=0)
  24. continue;
  25. for (k=1,temp=(unsigned long long)cnt,jj=(unsigned long long *)calloc(1000,sizeof(unsigned long long));1;k++)
  26. {
  27. free(jj);
  28. jj=(unsigned long long *)calloc(1000,sizeof(unsigned long long));
  29. if (cnt==1)
  30. {
  31. ii[0]=1;
  32. break;
  33. }
  34. jj[k-1]=temp;
  35. temp=f(temp);
  36. if (temp > (unsigned long long)j || temp<(unsigned long long) i)
  37. continue;
  38. if (ii[temp-i]!=0 || temp == 1)
  39. {
  40. for (l=k;l>=1;l--)
  41. {
  42. if (jj[l-1]>(unsigned long long)j || jj[l-1]<(unsigned long long)i)
  43. continue;
  44. else
  45. ii[jj[l-1]-1]=ii[temp-i]+k-l+1;
  46. }
  47. if (m<ii[jj[k-1]-1])
  48. {
  49. m=ii[jj[k-1]-1];
  50. printf("%lu\n",k);
  51. printf("%lu,%lu,%lu\n",jj[k-1],k,k);
  52.  
  53. }
  54. break;
  55. }
  56. }
  57. }
  58. free(ii);
  59. }
  60. return 0;
  61. }
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
Standard output is empty