版本比较
题解: P14304 【MX-J27-T1】分块
正文
增加 3 行删除 3 行
27 行未改动28293031323233343536373839403940414243442 行未改动27 行未改动using namespace std;#define int long longint q,n;signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);//q 也挺大的,建议加上。 ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);//q 也挺大的,建议加上。 cin>>q; while(q--) { cin>>n; int ans=0; int r=sqrt(n); ans+=(r-1)*3;//在 L 之前 int L=r*r,R=(r+1)*(r+1)-1,mid=(L+R)>>1;//R 一定要减 1,否则就变成了下一组数的开头。 ans+=(r-1)*3;//在 L 之前 int L=r*r,R=(r+1)*(r+1)-1,mid=(L+R)>>1;//R 一定要减 1,否则就变成了下一组数的开头。 ans+=(n>=L)+(n>=mid)+(n>=R);//这样写方便 cout<<ans<<'\n'; } return 0;2 行未改动