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;
}
全部评论
(0) 回帖