题解 | 智乃的数字 容斥 + 二分

智乃的数字

https://www.nowcoder.com/practice/8f1b8129db30467787167da1a589b324

#include <iostream>
using namespace std;

using LL = long long;

void solve(){
    int k;
    cin>>k;

    auto cal=[](LL n){
        LL a = (n>=5)+(n-5)/10;
        LL b = (n>=3)+(n-3)/6;
        LL c = (n>=15)+(n-15)/30;
        return a+b-c;
    };

    LL l=0,r=1e12;
    LL ans=-1;
    while(l<=r){
        LL mid=(l+r)/2;
        if(cal(mid)<k){
            ans=mid+1;
            l=mid+1;
        }else{
            r=mid-1;
        }
    }

    cout<<ans<<"\n";
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int t=1;
    cin>>t;
    while(t--)solve();
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

陌夏微秋:一线城市25w左右吧,17×15=255
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务