fork download
  1. //Bai 11
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. #define el "\n"
  6. #define ll long long
  7. #define ull unsigned long long
  8. #define se second
  9. #define fi first
  10. #define be begin()
  11. #define en end()
  12. #define Faster cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
  13. ll n;
  14. void Run()
  15. {
  16. int ok = 0;
  17. cin >> n;
  18. // a^2 + 2a - n = 0
  19. ll del = 2 * 2 - 4 * 1 * (-n);
  20. if(del < 0) cout << "NO", ok = 1;
  21. else
  22. {
  23. if(sqrt(del) * sqrt(del) != del) cout << "NO", ok = 1;
  24. else
  25. {
  26. ll x1 = (-2 + sqrt(del)) / 2;
  27. ll x2 = (-2 - sqrt(del)) / 2;
  28. if(x1 * (x1 + 2) == n) cout << x1, ok = 1;
  29. if(x2 * (x2 + 2) == n && ok == 0) cout << x2, ok = 1;
  30. }
  31. }
  32. if(ok == 0) cout << "NO";
  33. }
  34. int main()
  35. {
  36. Faster;
  37. Run();
  38. return 0;
  39. }
  40.  
  41.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty