Guest User

Untitled

a guest
Feb 7th, 2023
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.53 KB | None | 0 0
  1. #pragma GCC optimize("O3,unroll-loops")
  2. #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
  3.  
  4. #include "bits/stdc++.h"
  5. using namespace std;
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. #include <ext/pb_ds/tree_policy.hpp>
  8. using namespace __gnu_pbds;
  9. template<class key, class cmp = std::less<key>>
  10. using op_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
  11. #ifdef thunder
  12. #include "bug.h"
  13. #else
  14. #define bug(...)
  15. #endif
  16.  
  17. #define ll long long
  18. #define lld double
  19. #define all(x) x.begin(), x.end()
  20. #define iceil(n, x) (((n) + (x) - 1) / (x))
  21. #define goog(tno) cout << "Case #" << tno <<": "
  22.  
  23. const ll INF=2e18;
  24. const ll mod=1000000007;
  25. const ll maxn=1e6+10;
  26.  
  27. template< ll mod >
  28. struct ModInt {
  29.   ll x;
  30.   ModInt() : x(0) {}
  31.   ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  32.   ModInt &operator+=(const ModInt &p) {
  33.     if((x += p.x) >= mod) x -= mod;
  34.     return *this;
  35.   }
  36.   ModInt &operator-=(const ModInt &p) {
  37.     if((x += mod - p.x) >= mod) x -= mod;
  38.     return *this;
  39.   }
  40.   ModInt &operator*=(const ModInt &p) {
  41.     x = (int) (1LL * x * p.x % mod);
  42.     return *this;
  43.   }
  44.   ModInt &operator/=(const ModInt &p) {
  45.     *this *= p.inverse();
  46.     return *this;
  47.   }
  48.   ModInt operator-() const { return ModInt(-x); }
  49.   ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  50.   ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  51.   ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  52.   ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  53.   bool operator<(const ModInt &p) const { return x < p.x; }
  54.   bool operator>(const ModInt &p) const { return x > p.x; }
  55.   bool operator==(const ModInt &p) const { return x == p.x; }
  56.   bool operator!=(const ModInt &p) const { return x != p.x; }
  57.   string to_str() { return to_string(x); }
  58.   ModInt inverse() const {
  59.     ll a = x, b = mod, u = 1, v = 0, t;
  60.     while(b > 0) {
  61.       t = a / b;
  62.       swap(a -= t * b, b);
  63.       swap(u -= t * v, v);
  64.     }
  65.     return ModInt(u);
  66.   }
  67.   ModInt pow(int64_t n) const {
  68.     ModInt ret(1), mul(x);
  69.     while(n > 0) {
  70.       if(n & 1LL) ret *= mul;
  71.       mul *= mul;
  72.       n >>= 1LL;
  73.     }
  74.     return ret;
  75.   }
  76.   friend ostream &operator<<(ostream &os, const ModInt &p) {
  77.     return os << p.x;
  78.   }
  79.   friend istream &operator>>(istream &is, ModInt &a) {
  80.     int64_t t;
  81.     is >> t;
  82.     a = ModInt< mod >(t);
  83.     return (is);
  84.   }
  85.   static ll get_mod() { return mod; }
  86. };
  87. using mint = ModInt< mod >;
  88.  
  89. vector<ll> ok;
  90. vector<mint> pref;
  91.  
  92. void solve(){
  93.     ll l,r;
  94.     cin>>l>>r;
  95.     ll idx_l=upper_bound(all(ok),l)-ok.begin();
  96.     ll idx_r=upper_bound(all(ok),r)-ok.begin();
  97.  
  98.     auto ok=[](ll n)->bool{
  99.         ll x=cbrtl(n);
  100.         if(x*x*x==n) return 1;
  101.         return 0;
  102.     };
  103.  
  104.     // if(l==r){
  105.     //     if(!ok(l)){
  106.     //         cout<<0<<'\n';
  107.     //         return;
  108.     //     }else{
  109.     //         cout<<l<<'\n';
  110.     //     }
  111.     //     return;
  112.     // }
  113.     bug(idx_l,idx_r);
  114.     mint ans=pref[idx_r-1];
  115.     if(ok(l)) idx_l--;
  116.     ans-=pref[idx_l-1];
  117.     cout<<ans<<'\n';
  118. }
  119.  
  120. signed main(){
  121.     ios_base::sync_with_stdio(false), cin.tie(nullptr);
  122.     //freopen("input.txt","r",stdin);
  123.     //freopen("output.txt","w",stdout);
  124.     for(ll i=0;i<maxn;i++){
  125.         ok.push_back(i*i*i);
  126.     }
  127.     // bug(ok);
  128.     pref={ok[0]};
  129.     for(ll i=1;i<maxn;i++){
  130.         pref.push_back(pref.back()+ok[i]);
  131.     }
  132.     int t=1;
  133.     cin>>t;
  134.     for(int i=1;i<=t;i++){
  135.         solve();
  136.     }
  137.     return 0;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment