Codeforces 1374B. Multiply by 2, divide by 6 Solution

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

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 ...

Powered by Blogger.