Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int main()
- {
- int n;
- scanf("%d",&n);
- int i;
- for(i = 0; i<n; i++)
- {
- int c,d, cc =0;
- scanf("%d",&c);
- scanf("%d",&d);
- if(c == d)
- {
- printf("0\n");
- continue;
- }
- while(c>d)
- {
- //printf("\n c is greater than d with c - %d and d - %d\n",c,d);
- if(c % 2 == 0)
- c = c/2;
- else
- c = (c-1)/2;
- cc++;
- }
- double rr =log(c)/log(2);
- printf("Current value of rr is %lf\n",rr);
- while(!(rr == (int)rr))
- {
- printf("hung in loop with c = %d\n",c);
- if(c % 2 == 0)
- c = c/2;
- else
- c = (c-1)/2;
- rr = log(c)/log(2);
- cc++;
- }
- if(c == d)
- {
- printf("%d\n",cc);
- continue;
- }
- else if(d % c == 0 && c != 1)
- {
- double r = d/c;
- int a = (int)(log(r)/log(2));
- printf("%d",a+cc);
- continue;
- }
- else if(c == 1 && d%c == 0)
- {
- int cou = 0, mm = 1;
- while(mm != d)
- {
- cou++;
- mm *=2;
- }
- printf("%d\n",(cou+cc));
- continue;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment