签到题这里久懒得写了。

B - 缺失的数据范围

Total Submission(s): 2602    Accepted Submission(s): 559

题意:求最大的N,满足N^a*[log2(N)]^b<=K;

思路:二分即可,log2要手写,然后就是注意判pow是否超过long long。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1000100;
const ll inf=1e18;
ll A,B,K,ans,aa[61];
ll Log(ll x){
    int pos=lower_bound(aa+1,aa+60+1,x)-aa;
    return pos;
}
bool check(ll x){
    ll a=1,res=1;
    ll b=Log(x);// cout<<b<<" "<<aa[b]<<" ";
    for(int i=1;i<=A;i++){
        if(a>K/x) return false;
        a=a*x; if(a>K) return false;
    }
    for(int i=1;i<=B;i++){
        if(res>K/b) return false;
        res=res*b; if(res>K) return false;
    }
    //cout<<a<<" "<<b<<endl;
    if(a>K/res) return false;
    if(a*res<=K) return true;
}
int main()
{
    int T;
    aa[0]=1;
    for(int i=1;i<=60;i++) aa[i]=aa[i-1]*2;
    scanf("%d",&T);
    while(T--){
        scanf("%lld%lld%lld",&A,&B,&K); ans=0;
        ll L=1,R=K;
        while(L<=R){
            ll Mid=(L+R)/2;
            if(check(Mid)) ans=Mid,L=Mid+1;
            else R=Mid-1;
        }
        printf("%lld\n",ans);
    }
    return 0;
}
View Code

相关文章:

  • 2021-08-27
  • 2021-12-23
  • 2022-12-23
  • 2021-06-15
  • 2022-01-02
  • 2021-06-17
  • 2021-05-25
  • 2021-08-07
猜你喜欢
  • 2022-12-23
  • 2019-02-17
  • 2021-09-23
  • 2021-10-26
相关资源
相似解决方案