CF 1419B Stairs (数论/找规律)

B. Stairs

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Jett is tired after destroying the town and she wants to have a rest. She likes high places, that's why for having a rest she wants to get high and she decided to craft staircases.

A staircase is a squared figure that consists of square cells. Each staircase consists of an arbitrary number of stairs. If a staircase has nn stairs, then it is made of nn columns, the first column is 11 cell high, the second column is 22 cells high, ……, the nn-th column if nn cells high. The lowest cells of all stairs must be in the same row.

A staircase with n stairs is called nice, if it may be covered by n disjoint squares made of cells. All squares should fully consist of cells of a staircase.

This is how a nice covered staircase with 7 stairs looks like:

Find out the maximal number of different nice staircases, that can be built, using no more than xx cells, in total. No cell can be used more than once.

Input

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

The description of each test case contains a single integer xx (1≤x≤1018)(1≤x≤1018)  — the number of cells for building staircases.

Output

For each test case output a single integer  — the number of different nice staircases, that can be built, using not more than xx cells, in total.

Example

input

Copy

4
1
8
6
1000000000000000000

output

Copy

1
2
1
30

Note

In the first test case, it is possible to build only one staircase, that consists of 11 stair. It's nice. That's why the answer is 11.

In the second test case, it is possible to build two different nice staircases: one consists of 11 stair, and another consists of 33 stairs. This will cost 77 cells. In this case, there is one cell left, but it is not possible to use it for building any nice staircases, that have not been built yet. That's why the answer is 22.

In the third test case, it is possible to build only one of two nice staircases: with 11 stair or with 33 stairs. In the first case, there will be 55 cells left, that may be used only to build a staircase with 22 stairs. This staircase is not nice, and Jett only builds nice staircases. That's why in this case the answer is 11. If Jett builds a staircase with 33 stairs, then there are no more cells left, so the answer is 11 again.

 

题解:观察规律易得出,满足条件的stair 分别为1 3 7 15...... 即2^n-1

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string.h>
using namespace std;
long long a[64];


long long getnum(long long x)
{
	return((1+x)*x/2);
}
	
void init()
{
	long long x=1;
	for (int i=1;i<=63;i++)
	{
		x*=2;
		a[i]=x-1;
	}
}

int main()
{
	init();
	int t;
	cin>>t;
	for (int tt=1;tt<=t;tt++)
	{
		long long n;
		cin>>n;
		int total=0,i=1;
		long long now=getnum(a[i]);
		while (n>=now)
		{
			
			n-=now;
			i++;
			total++;
			now=getnum(a[i]);
		}
		cout<<total<<endl;
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值