Coeforces 1362A. Johnny and Ancient Computer

Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. long long t,n,r,a,b,a1,b1,f,c;
  6. cin>>t;
  7. while(t--)
  8. {
  9. int c=0;
  10. cin>>a1>>b1;
  11. b=max(a1,b1);
  12. a=min(a1,b1);
  13. r=b/a+b%a;
  14. while(r%8==0)
  15. {
  16. r=r/8;
  17. c++;
  18. }
  19. while(r%4==0)
  20. {
  21.  
  22. r=r/4;
  23. c++;
  24. }
  25. while(r%2==0)
  26. {
  27.  
  28. r=r/2;
  29. c++;
  30. }
  31. if(r!=1||b%a!=0)
  32. cout<<"-1"<<endl;
  33. else
  34. cout<<c<<endl;
  35. }
  36. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.