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. #include<iomanip>
  15. // 2D vector vector<vector<int>>v(n,vector<int>(m));
  16. // sort and reverse in vector sort(v.begin(), v.end(), greater<int>());
  17. // str.erase(pos,len); erase in string
  18. // a = s.substr(0, i)<<before i, b = s.substr(i)<<from i to end;
  19. // cout << (v[0] == 1 ? "YES" : "NO") << endl;
  20. // unsigned long long int
  21. // priority_queue<ll, vector<ll>, greater<ll>> p;
  22. using namespace std;
  23. #define ll long long
  24. #define all(c) c.begin(),c.end()
  25.  
  26.  
  27. ll gcd(ll a, ll b)
  28. {
  29. while (b != 0)
  30. {
  31. ll a2 = a;
  32. a = b; b = a2 % b;
  33. }
  34. return a;
  35. }
  36.  
  37. ll lcm(ll a, ll b)
  38. {
  39. return a / gcd(a, b) * b;
  40. }
  41.  
  42. void soso()
  43. {
  44. ios::sync_with_stdio(0);
  45. cin.tie(NULL);
  46. cout.tie(NULL);
  47. }
  48.  
  49. vector<ll>arr(200005);
  50. int main()
  51. {
  52. soso();
  53. for (ll i = 0; i < 100004; i++)
  54. arr[i] = (i * (i + 1)) / 2;
  55.  
  56. int t; cin >> t;
  57. while (t--)
  58. {
  59. ll l, r,ans=0; cin >> l >> r;
  60. for (int i = 1; i < 10004; i++)
  61. {
  62. ll sm = l - arr[i],grat=r-arr[i];
  63. if (grat < 0)break;
  64. ll lo = lower_bound(arr.begin()+1, arr.end(), sm) - arr.begin();
  65. ll upp = (upper_bound(arr.begin()+1, arr.end(), grat) - arr.begin())-1;
  66. cout << sm << " " << lo << " " << grat << " " << upp << "\n";
  67.  
  68. ans += (upp - lo) + 1;
  69. }
  70. cout << ans/2 << "\n";
  71. }
  72. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty