fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool transform(int a,int b,int i,vector<int>update){
  5.  
  6. if(a>b){
  7. return false;
  8. }
  9.  
  10. if(a==b){
  11. update.push_back(b);
  12. return true;
  13. }
  14.  
  15. if(transform(a*2,i+1,b,update)){
  16. update.push_back(a);
  17. return true;
  18. }
  19. if(transform(a*10+1,i+1,b,update)){
  20. update.push_back(a);
  21. return true;
  22. }
  23. return false;
  24. }
  25. int main() {
  26. int a,b;
  27. cin>>a>>b;
  28. vector<int>update;
  29. int i = 1;
  30. if(transform(a,b,i,update)){
  31.  
  32. cout<<"Yes"<<i<<endl;
  33. }
  34. else
  35.  
  36. cout<<"NO";
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5320KB
stdin
2     162
stdout
NO