Display The Number (CodeForces - 1295A)

传送门

You have a large electronic screen which can display up to 998244353998244353 decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of 77 segments which can be turned on and off to compose different digits. The following picture describes how you can display all 1010 decimal digits:

As you can see, different digits may require different number of segments to be turned on. For example, if you want to display 11, you have to turn on 22 segments of the screen, and if you want to display 88, all 77 segments of some place to display a digit should be turned on.

You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than nn segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than nn segments.

Your program should be able to process tt different test cases.

Input

The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases in the input.

Then the test cases follow, each of them is represented by a separate line containing one integer nn (2≤n≤1052≤n≤105) — the maximum number of segments that can be turned on in the corresponding testcase.

It is guaranteed that the sum of nn over all test cases in the input does not exceed 105105.

Output

For each test case, print the greatest integer that can be displayed by turning on no more than nn segments of the screen. Note that the answer may not fit in the standard 3232-bit or 6464-bit integral data type.

Example

Input

2
3
4

Output

7
11

 

题意:一个电子屏幕上可以显示一个数字,分别需要一定数量的片段(如图,显示“1”需要两个片段)。问提供n个片段时,最大可以显示一个多大的数字。

题解:如图我们可以列出,显示“0”需要6段,显示“1”需要2段,往后依次是5段、5段、4段、5段、6段、3段、7段、6段。片段数量一定时,我们可以通过选择相同片段中较大的数字(比如5段可以显示“2”、“3”、“5”,选择“5”为最佳),还可以通过将一定量的片段拆分组成更多位的数字(比如4段可以显示“4”,但我们可以拆分成两个2段来显示“11”)。两种方法一比较,方法很显然是,有条件的情况下尽可能选择更多位数字,否则则取一定量片段中最大的数字。

其中最小的两个分别是2段的“1”和3段的“7”,显然这两个数字是“最经济的”,我们只要这两个数字即可。选择方法便是当片段数量是偶数时,全吧用来显示“1”;当片段数是奇数时,留有三段用来显示“7”,其余全显示“1”。

#include<iostream>
using namespace std;
int t, n;
int main(){
	scanf("%d", &t);
	while(t--){
		scanf("%d", &n);
		int d = n%2==1? (n/2-1): n/2;
		if(n%2)	printf("7");
		for(int i=0; i<d; i++)
			printf("1");
		printf("\n");
	}
	return 0;
}

 

 

展开阅读全文
©️2020 CSDN 皮肤主题: 书香水墨 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值