Coeforces 1362A. Johnny and Ancient Computer
Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- long long t,n,r,a,b,a1,b1,f,c;
- cin>>t;
- while(t--)
- {
- int c=0;
- cin>>a1>>b1;
- b=max(a1,b1);
- a=min(a1,b1);
- r=b/a+b%a;
- while(r%8==0)
- {
- r=r/8;
- c++;
- }
- while(r%4==0)
- {
- r=r/4;
- c++;
- }
- while(r%2==0)
- {
- r=r/2;
- c++;
- }
- if(r!=1||b%a!=0)
- cout<<"-1"<<endl;
- else
- cout<<c<<endl;
- }
- }
No comments