Very Suspicious

Sehr Sus is an infinite hexagonal grid as pictured below, controlled by MennaFadali, ZerooCool and Hosssam.

They love equilateral triangles and want to create nn equilateral triangles on the grid by adding some straight lines. The triangles must all be empty from the inside (in other words, no straight line or hexagon edge should pass through any of the triangles).

You are allowed to add straight lines parallel to the edges of the hexagons. Given nn, what is the minimum number of lines you need to add to create at least nn equilateral triangles as described?

Adding two red lines results in two new yellow equilateral triangles.

Input

The first line contains a single integer tt (1≤t≤1051≤t≤105) — the number of test cases. Then tt test cases follow.

Each test case contains a single integer nn (1≤n≤1091≤n≤109) — the required number of equilateral triangles.

Output

For each test case, print the minimum number of lines needed to have nn or more equilateral triangles.

Example

input

Copy

4
1
2
3
4567

output

Copy

2
2
3
83

Note

In the first and second test cases only 2 lines are needed. After adding the first line, no equilateral triangles will be created no matter where it is added. But after adding the second line, two more triangles will be created at once.

In the third test case, the minimum needed is 3 lines as shown below.

思路:这个题不是说是正六边形,要找到正三角形,我们可以从角度入手,我们是不是只要凑出60度角即可,因为要平行边所以相当于只有3种边,1.平行x轴。2.与x轴夹角60度。3.与x轴夹角120度。我们的边只有这3种选择,我们是不是只要将两条边的夹角凑成60度就会有一个等边三角形,因为另一条边是六边形的边。有一个60度形成,就会有两个等边三角形,因为它的对角也是60度。然后就是边与边的关系(组合),假设三个边为x,y,z 。三个边的组合有,x与y,y与z,x与z,而且以上述的三种边组合,只要它们相交就一定会有60度,所以只要知道x这种边的个数,乘以y这种边的个数,同理推其余两种。有60度就是有两三角形,所以就会有 2*(x*y + y*z + x*z),然后就是x,y,z三种边越平均越好,每次都是不同种类就能有更多交点,所以不同种的边一个一个排下来就好,均匀分配,n个边不能被整除时就让它们添上一点,不要浪费,不害怕角多。那么我们直接二分边数找到最大中的最小即可。

完整代码:

#include <bits/stdc++.h>

using namespace std;

#define int long long
const int mod=1e9+7;

int check(int mid)
{
    int x=mid/3,y=mid/3,z=mid/3;
    if(x+y+z<mid)x++;
    if(x+y+z<mid)y++;
    if(x+y+z<mid)z++;
    return 2*(x*y+y*z+x*z);
}

void solve()
{
    int n;
    cin>>n;
    int l=0,r=1e5;
    while(l<r)
    {
        int mid=l+r>>1;
        if(check(mid)>=n)r=mid;
        else l=mid+1;
    }
    cout<<r<<endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值