思路
将当前数开根,在其前的每个正整数都有三个对应的数。
例如:
、、 有因数 ;
、、 有因数 ;
、、 有因数 ;
、、 有因数 。
因此每个因数都对应 个正整数。
代码
#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;
}