Codeforces Round #671 (Div. 2) B. Stairs

Description

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 n stairs, then it is made of n columns, the first column is 1 cell high, the second column is 2 cells high, …, the n-th column if n 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 x cells, in total. No cell can be used more than once.

Input

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

The description of each test case contains a single integer x (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 x cells, in total.

Example
input

4
1
8
6
1000000000000000000

output

1
2
1
30

Note

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

In the second test case, it is possible to build two different nice staircases: one consists of 1 stair, and another consists of 3 stairs. This will cost 7 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 2.

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

题意: Jett 想要拼成美丽的阶梯,每个美丽的阶梯都是由12、12+22、12+22+32、12+22+32+42……加上其中的一项构成的。比如这种就不算美丽的阶梯:在这里插入图片描述
上图是由一个1*1的和一个1*2的矩形构成的,不符合美丽的阶梯的要求,所以不算。现输入一个测试数 t ,然后接下来是有t个测试数据的输入,每个数据的意思是总共有几个小正方形,比如示例中的第二个测试数据是8,则说明总共有8个小正方形,求最多能够构成几个美丽的阶梯。我们用示例的第二个数8来说明一下:如果我们可以用1个小正方形,这样就能砌成一个美丽的阶梯,然后还剩下7个小正方形(如果已经存在一个状态的美丽阶梯,则不再重复堆砌),我们可以用这7个小正方形中的6个又堆砌成下图的美丽正方形:
在这里插入图片描述
这样最后还剩下一个没有使用,因为1*1的美丽阶梯已经砌过了,不能重复堆砌,所以8最多块小正方形最多堆砌2个美丽阶梯。

题解: 我们直接根据题意找规律,砌第一个美丽阶梯要一块砖头,砌第二个美丽阶梯要 (2*1+1)*((2*1+1)+1)/2块砖头……令最开始砌第一个美丽阶梯需要的砖头数目为n(即n=1),第二个美丽阶梯需要的砖头数目为 n = (2*n+1) → \rightarrow n * (n+1) → \rightarrow 即 3*(1+3)/2 == 6 块砖头。再接着往下一个美丽阶梯需要 2*3+1 == 7 → \rightarrow 7 * (1+7) / 2 == 28 块砖头。所以根据这个规律就可以把程序写出来了。

c++ AC 代码

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		long long k;
		scanf("%lld", &k);
		int ans = 0;
		for (long long n = 1; n * (n + 1) / 2 <= k; n = 2 * n + 1)
		{
			k -= n * (n + 1) / 2;
			ans++;
		}
		printf("%d\n", ans);
	}
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值