Advertisement
Guest User

Untitled

a guest
Sep 26th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. const int N = 1e5+2;
  5. long long sum [N] ;
  6. int main()
  7. {
  8.     int n ;
  9.     long long ans;
  10.     long long *srch;
  11.     for (int i = 0 ; i<N ; ++i)
  12.     {
  13.         sum[i] = (1ll*i*(i+1))/2.0;
  14.     }
  15.     i:
  16.     cin >> n ;
  17.     n = (n<0 ? -n : n);
  18.     srch = lower_bound(sum,sum+N,n);
  19.     ans = srch - sum ;
  20.     if (*srch != n) ++ans;
  21.     if (*srch != n && n&1 ) ++ans;
  22.     cout << ans <<endl ;
  23.     goto i ;
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement