fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void func(int x, int y)
  6. {
  7. int d = (y + x) / 2;
  8. int i = 0;
  9. int cx = x;
  10. int cy = y;
  11. while(cx + i <= d)
  12. {
  13. cx += i;
  14. cy -= i++;
  15. }
  16.  
  17. cout << "i-1: " << i-1 << endl;
  18. cout << "cy:" << cy << endl;
  19. cout << "cx:" << cx << endl;
  20. if(cy - cx == 0)
  21. cout << (i - 1) * 2 << endl;
  22. else if(cy - cx <= i)
  23. cout << (i - 1) * 2 + 1 << endl;
  24. else
  25. cout << i * 2 << endl;
  26.  
  27.  
  28.  
  29. }
  30.  
  31. int main(void) {
  32. func(0, 4);
  33. return 0;
  34. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
i-1: 1
cy:3
cx:1
3