题解:P14304 【MX-J27-T1】分块
Wangyixi007 · · 题解
Update on 2025/10/28 修改了代码中的 sqrt 为 sqrtl,能够通过 hack 数据
0x00 暴力
考虑从
期望得分:
0x01 正解
首先注意到假设有一个非零自然数
所以我们考虑在区间
因为在区间
所以在区间
然后再考虑一般情况:
首先,我们一定能求出一个
所以甚至可以总结公式:
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int t,n;
int sum,ans,num;
cin>>t;
while(t--){
cin>>n;
sum=floor(sqrtl(n));
ans=(sum-1)*3;
num=sum*sum;
ans+=(n-num+sum)/sum;
cout<<ans<<'\n';
}
return 0;
}
时间复杂度:
预期得分: