Guest User

Untitled

a guest
Apr 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include<cstdio>
  2. using namespace std;
  3. const int MAX=1000006;
  4. int dist[MAX];
  5. bool vis[MAX];
  6. void prep(int num,int ndis)
  7. {
  8.     dist[num]=ndis;
  9.     if ((num-1)%3 == 0 && num>4 && ((num-1)/3)%2==1 && !vis[(num-1)/3])
  10.     {
  11.         vis[(num-1)/3]=1;
  12.         prep((num-1)/3,ndis+1);
  13.     }
  14.     if ((num*2)<MAX && !vis[num*2])
  15.     {
  16.         vis[num*2]=1;
  17.         prep(num*2,ndis+1);
  18.     }
  19. }
  20. int main()
  21. {
  22.     int a,b,cmax;
  23.     prep(1,1);
  24.     while (0<scanf("%d%d",&a,&b))
  25.     {
  26.         cmax=0;
  27.         for (int i=a;i<=b;++i)
  28.             if (cmax<dist[i])
  29.                 cmax=dist[i];
  30.         printf("%d %d %d\n",a,b,cmax);
  31.  
  32.     }
  33. return 0;
  34. }
Add Comment
Please, Sign In to add comment