D题

D题为什么按照视频里讲的直接相减就不能ac,还要加将sqrt(n)+1,然后除最后再加1呢,这两行不是一样的吗?
cnt += n/cnt-n/x;
// cnt += n/(cnt+1)-n/x+1;

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
#define ll long long
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        ll n,x;
        scanf("%lld%lld",&n,&x);
        if(x<=sqrt(n)){
            printf("%d\n",x);
        }
        else{
            ll cnt = floor(sqrt(n));
            cnt += n/cnt-n/x;
           // cnt += n/(cnt+1)-n/x+1;
            printf("%lld\n",cnt);
        }
    }
    return 0;
}



全部评论

相关推荐

我以为牛客上有美团题库是秋招人都知道的事儿......&nbsp;没想到在XHS上刷到了室友评论了卖美团题库的人求资料&nbsp;秋招信息壁垒这么严重吗???
10yi:信息就在那里,只是缺少主动搜集信息的能力,我相信去百度一下都能知道哪里有题库,而不是遇到问题首先想有没有人帮我做
点赞 评论 收藏
分享
砸砸无所畏惧:同字节耐面王 不同部门一起面了十几轮 最后放弃了 有个面试官透露面评都是算法能力不达预期
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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