holiday/8.13/B-Suspicious/Suspicious.cpp
2022-08-13 14:22:41 +08:00

66 lines
856 B
C++

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=1e9+5,M=4e4;//const
int ans[M],dp[3][3],t,n,len;
void pre()
{
ans[1]=0;
ans[2]=2;
ans[3]=6;
dp[0][1]=1;
dp[1][1]=1;
dp[2][1]=1;
bool b=1;
for(int i=4;b;i+=3)
{
for(int j=0;j<3;j++)
{
dp[j][1]++;
int r=(j+1)%3,l=(r+1)%3;
ans[i+j]=ans[i+j-1]+dp[l][1]*2+dp[r][1]*2;
// printf("%d:%d\n",i+j,ans[i+j]);
if(ans[i+j]>=N-5)
{
b=0;
len=i+j;
break;
}
}
}
}
int find(int u,int l,int r)
{
int mid=(l+r)/2;
if(l==r)
{
return l;
}
if(ans[mid]==u)
{
return mid;
}
if(u<ans[mid])
{
return find(u,l,mid);
}
else
{
return find(u,mid+1,r);
}
}
int main()
{
// freopen("bout.txt","w",stdout);
pre();
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
printf("%d\n",find(n,1,len));
}
return 0;
}