首页 > 其他分享 >6-1891D-Suspicious logarithms

6-1891D-Suspicious logarithms

时间:2023-11-22 19:47:18浏览次数:39  
标签:ck logarithms int res 1891D Suspicious long inf ll

题意:

思路:
分块 , 先对f(x) 相同的分块, 在对g(x)相同的分块,注意爆long lnog
代码:

点击查看代码
#include <bits/stdc++.h>
#define int long long 
using namespace std;
typedef pair<int,int> pll;
typedef tuple<int,int,int> TP;
const int N = 1e7 + 10;
int inf=1e9+7;
int ck(int x,int w)
{
  //  cout<<x<<" "<<w<<"dsa\n";
    int res=1;
    int cnt=0;
    while(w*res<=x)
    {
        res=res*w;
        cnt++;
    }
    return cnt;
}
int js(int a,int b,int c)
{
    int res=0;
   // int d=c;
    int d=c;
    for(int i=1;i<64;i++)
    {   
        if(d>b)
        {
            break;
        } 
        if((__int128)d*c>(__int128)1*1e18)
        {
             int w=min(1000000000000000000,b)-max((int)d,a);
           // cout<<w<<"\n";
            if(w>=0)res+=(w+1)%inf*i;
        
            res=res%inf;
            break;
        }
        int w=min(d*c-1,b)-max((int)d,a);
       // cout<<w<<"\n";
        if(w>=0)res+=(w+1)%inf*i;
    
        d=d*c;
        res=res%inf;
        // res+=w*i;
    }
    return res;
}
int poww(int x)
{
    int res=1;
    while(x--)
    {
        res=res*2;
    }
    return res;
}
void solve()
{
    int l,r;
    cin>>l>>r;
    int ll,rr;
    ll=ck(l,2);
    rr=ck(r,2);
    int ans=0;
    for(int i=ll;i<=rr;i++)
    {
        int a,b;
        a=max(l,poww(i));
        b=min(r,poww(i+1)-1);
        ans=(ans+js(a,b,i))%inf;
    }
    cout<<ans<<"\n";
}
signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t=1;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0 ^ 0;
}

标签:ck,logarithms,int,res,1891D,Suspicious,long,inf,ll
From: https://www.cnblogs.com/xxj112/p/17850121.html

相关文章