B. Captain Flint and a Long Voyage
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to come up with an interesting problem and asked the crew to solve it.
In the beginning, uncle Bogdan wrote on a board a positive integer x consisting of n digits. After that, he wiped out x and wrote integer k instead, which was the concatenation of binary representations of digits x consists of (without leading zeroes). For example, let x=729, then k=111101001 (since 7=111, 2=10, 9=1001).
After some time, uncle Bogdan understood that he doesn’t know what to do with k and asked Denis to help. Denis decided to wipe last n digits of k and named the new number as r.
As a result, Denis proposed to find such integer x of length n that r (as number) is maximum possible. If there are multiple valid x then Denis is interested in the minimum one.
All crew members, including captain Flint himself, easily solved the task. All, except cabin boy Kostya, who was too drunk to think straight. But what about you?
Note: in this task, we compare integers (x or k) as numbers (despite what representations they are written in), so 729<1999 or 111<1000.
Input
The first line contains a single integer t (1≤t≤1000) — the number of test cases.
Next t lines contain test cases — one per test case. The one and only line of each test case contains the single integer n (1≤n≤105) — the length of the integer x you need to find.
It’s guaranteed that the sum of n from all test cases doesn’t exceed 2⋅105.
Output
For each test case, print the minimum integer x of length n such that obtained by Denis number r is maximum possible.
Example
inputCopy
2
1
3
outputCopy
8
998
Note
In the second test case (with n=3), if uncle Bogdan had x=998 then k=100110011000. Denis (by wiping last n=3 digits) will obtain r=100110011.
It can be proved that the 100110011 is the maximum possible r Denis can obtain and 998 is the minimum x to obtain it.
c++入门练习题曾有一道类似的题目。
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int main() { int t; scanf("%d",&t); for(int i=1;i<=t;i++) { int n; scanf("%d",&n); int _8=n/4+bool(n%4); for(int i=1;i<=n;i++) { if(i<n-_8+1)printf("9"); else printf("8"); } printf("\n"); } }
- American Option Pricing via Longstaff and Schwartz (2001)
- unsigned char _interlockedbittestandset(long volatile *a, long b)问题
- "Argument list too long": Beyond Arguments and Limitations
- (又FST在long long!!)Codeforces Round #293 (Div. 2)C. Anya and Smartphone
- 【论文阅读笔记】CVPR2015-Long-term Recurrent Convolutional Networks for Visual Recognition and Description
- ‘Skimming-Perusal’ Tracking: A Framework for Real-Time and Robust Long-term Tracking
- 湖南大学ACM程序设计新生杯大赛(同步赛)H-Yuanyuan Long and His Ballons【公式】
- Oracle LONG and LONG RAW Causing “Stream has already been closed” Exception 7fe8
- "Argument list too long": Beyond Arguments and Limitations
- American Option Pricing via Longstaff and Schwartz (2001)
- HiWords and LoWords from Long Values
- 湖南大学ACM程序设计新生杯大赛(同步赛)H-Yuanyuan Long and His Ballons【公式】
- JSON Bean互转 (Timestamp 2 Long and Long 2 Timestamp)
- 湖南大学ACM程序设计新生杯大赛 - Yuanyuan Long and His Ballons(环形染色问题)
- Java and unsigned int, unsigned short, unsigned byte, unsigned long, etc.
- no interview, just written test and long time waiting ...
- Determine the ranges of char , short , int , and long variables
- 湖南大学ACM程序设计新生杯大赛(同步赛)H - Yuanyuan Long and His Ballons
- _int64 and long long 区别【转载】
- What are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet?