题解:P14304 【MX-J27-T1】分块
Wh_Dawn
·
·
题解
思路
将当前数开根,在其前的每个正整数都有三个对应的数。
例如:
$4$、$6$、$8$ 有因数 $2$;
$9$、$12$、$15$ 有因数 $3$;
$16$、$20$、$24$ 有因数 $4$。
因此每个因数都对应 $3$ 个正整数。
# **代码**
```cpp
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T&x){
x=0;char c;int sign=1;
do{c=getchar();if(c=='-') sign=-1;} while(!isdigit(c));
do{x=x*10+c-'0';c=getchar();}while(isdigit(c));
x*=sign;
}
long long t,n,x,y,z,ans;
int main()
{
read(t);
while(t--)
{
read(n);
x=sqrt(n);
ans=(x-1)*3;
if(x*x==n) ans+=1;
else
{
y=x+1,z=x+2;
if(x*x<=n) ans+=1;
if(x*y<=n) ans+=1;
if(x*z<=n) ans+=1;
}
cout<<ans<<'\n';
}
return 0;
}