fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <stdio.h>
  5.  
  6. using namespace std;
  7.  
  8. void fast_io(){
  9. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  10. }
  11.  
  12. int main()
  13. {
  14. fast_io();
  15. long long Sn;
  16. #ifdef ONLINE_JUDGE
  17. cin >> Sn;
  18. #endif
  19. #ifndef ONLINE_JUDGE
  20. Sn = 15;
  21. #endif
  22. // n^2 + n - 2Sn = 0
  23. double n1 = (-1+sqrt(1-(4*1*-2*Sn)))/2;
  24. double n2 = (-1-sqrt(1-(4*1*-2*Sn)))/2;
  25. cout << floor(max(n1, n2));
  26. }
  27.  
Success #stdin #stdout 0.01s 5284KB
stdin
15
stdout
5