fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. #define mp make_pair
  5. #define nline cout<<"\n"
  6. #define fast ios_base::sync_with_stdio(false),cin.tie(0)
  7. #define ain(A, B, C) assert(IN(A, B, C))
  8. #define ull unsigned long long int
  9. #define ll long long int
  10. #define pii pair<int,int>
  11. #define MAXX 100009
  12. #define fr(a,b,i) for(int i=a;i<b;i++)
  13. vector<int>G[MAXX];
  14. ull a,b;
  15. double ans;
  16. map<double,int>dis;
  17. int bfs(double src)
  18. {
  19. queue<double>q;
  20. q.push(src);
  21. dis[src]=1;
  22. while(not q.empty())
  23. {
  24. double s=q.front();
  25. if(abs(s-ans)<1e-6)return dis[s];
  26. double t=(double)((s*1.0)/(s+1.0));
  27. q.push(t);
  28. dis[t]=dis[s]+1;
  29. q.push(s+1);
  30. dis[s+1]=dis[s]+1;
  31. }
  32. }
  33. int main()
  34. {
  35. cin>>a>>b;
  36. ans=(double)((a*1.0)/b);
  37. int anss=bfs(1.0);
  38. cout<<anss<<endl;
  39. return 0;
  40. }
  41.  
  42.  
Time limit exceeded #stdin #stdout 5s 1014272KB
stdin
Standard input is empty
stdout
Standard output is empty