CPP   44
check num
Guest on 11th September 2023 07:44:34 AM


  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. int aa=0;
  4. int main(){
  5.         int a,b,i,m,n;
  6.         int hold,stay;
  7.         int ans[100000]={0};
  8.         int check(int,int);
  9.         /*scanf("%d%d",&a,&b);
  10.         printf("%d %d",a,b);
  11.         if(a<b){
  12.                 hold=a;
  13.                 a=b;
  14.                 b=hold;
  15.         }
  16.         for(i=0;b<=a;b++,i++){
  17.                 ans[i]=check(b,0);
  18.                 printf("%d\n",check(b,0));
  19.         }
  20.         for(m=0;m<=(a-b);m++){
  21.                 for(n=0;n<=(a-b);n++){
  22.                         if(ans[n]<ans[n+1]){
  23.                                 stay=ans[n];
  24.                                 ans[n+1]=ans[n];
  25.                                 ans[n]=stay;
  26.                         }
  27.                 }
  28.         }
  29.         printf("%d",ans[0]);*/
  30.        
  31.         printf("%d %d",check(22,0),aa);
  32.         system("pause");
  33.         return 0;
  34. }
  35. int check(int num,int total){
  36.         aa=aa+1;
  37.         printf("%d %d\n",num,total);
  38.         if(num==1)
  39.                 return total+1;
  40.         else{
  41.             if(num%2>0)
  42.                     check(num*3+1,total+1);
  43.             if(num%2==0)
  44.                     check(num/2,total+1);
  45.         }
  46. }

Raw Paste

Login or Register to edit or fork this paste. It's free.