fork(3) download
  1. /*input
  2. 4
  3. 1
  4. 3
  5. 5
  6. 7
  7. */
  8. #include <bits/stdc++.h>
  9. using namespace std;
  10. int step = 0;
  11. int f(int x,int y){
  12. if(y != 0) step += x/y - (y==1);
  13. if (y == 0) return x;
  14. return f(y,x%y);
  15. }
  16. int main(){
  17. ios_base::sync_with_stdio(false);cin.tie();
  18. int test;cin>>test;
  19. while (test--){
  20. int n;cin>>n;
  21. int ans = n-1;
  22. for(int i=n/2;i<n;++i){
  23. step = 0;
  24. if (f(n,i) == 1){
  25. ans = min (ans , step);
  26. }
  27. }
  28. cout << ans << '\n';
  29. }
  30. }
Time limit exceeded #stdin #stdout 5s 3456KB
stdin
Standard input is empty
stdout
Standard output is empty