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;
}
	

全部评论
当n=10200时就不一样,我觉得+1是为了确保n/(sqrt(n)+1)<sqrt(n),而不+1则是>=sqrt(n) (虽然我也没做出来🙃
点赞 回复 分享
发布于 2021-02-05 19:48

相关推荐

07-11 13:16
湖南工学院 Java
坚定的芭乐反对画饼_...:谁也不知道,毕竟现在的互联网和十年前已经完全不同了,谁都无法预测未来
点赞 评论 收藏
分享
认真搞学习:28小登的建议,投算法岗不要写什么物理竞赛,互联网+,多写点项目,用什么算法做了什么。还有本科算法是不可能的开发你这个也没有项目啊
点赞 评论 收藏
分享
昨天 16:52
已编辑
门头沟学院 Java
周五投的,流程今天结束
投递地平线等公司8个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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