fork download
  1. //Believe in yourself ,( try and try and then try ), You can do it
  2. //You don't have to be great to start but you have to start to be great
  3. #include <iostream>
  4. #include<algorithm>
  5. #include<cmath>
  6. #include<string>
  7. #include<vector>
  8. #include <utility>
  9. #include <stack>
  10. #include <set>
  11. #include <map>
  12. #include<queue>
  13. #include<set>
  14. // 2D vector vector<vector<int>>v(n,vector<int>(m));
  15. // sort and reverse in vector sort(v.begin(), v.end(), greater<int>());
  16. // str.erase(pos,len); erase in string
  17. // a = s.substr(0, i)<<before i, b = s.substr(i)<<from i to end;
  18. // cout << (v[0] == 1 ? "YES" : "NO") << endl;
  19. // unsigned long long int
  20. // priority_queue<ll, vector<ll>, greater<ll>> p;
  21. using namespace std;
  22. #define ll long long
  23. #define all(c) c.begin(),c.end()
  24.  
  25.  
  26. ll gcd(ll a, ll b)
  27. {
  28. while (b != 0)
  29. {
  30. ll a2 = a;
  31. a = b; b = a2 % b;
  32. }
  33. return a;
  34. }
  35.  
  36. ll lcm(ll a, ll b)
  37. {
  38. return a / gcd(a, b) * b;
  39. }
  40.  
  41. void soso()
  42. {
  43. ios::sync_with_stdio(0);
  44. cin.tie(NULL);
  45. cout.tie(NULL);
  46. }
  47.  
  48. ll sum(ll mid)
  49. {
  50. return (mid * (mid + 1)) / 2;
  51. }
  52. int main()
  53. {
  54. soso();
  55. int t; cin >> t;
  56. while (t--)
  57. {
  58. ll x; cin >> x;
  59. ll l = 1, r = 1e19, ans = 0;
  60. while (l <= r)
  61. {
  62. ll mid = (l + r) / 2;
  63. if (x > sum(mid))l = mid + 1;
  64. else
  65. {
  66. ll l22 = sum(mid - 1)+1, r22 = sum(mid);
  67. while (l22 <= r22)
  68. {
  69. ll mid22 = (l22 + r22) / 2;
  70. if (mid22 == x) { ans = mid; break; }
  71. if (mid22 < x)l = mid22 + 1;
  72. if (mid22 > x)r = mid22 - 1;
  73. }
  74. if (ans == 0)r = mid - 1;
  75. else break;
  76. }
  77. }
  78. cout << ans << "\n";
  79. }
  80.  
  81. }
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
Standard output is empty