934B. A Prosperous Lot

Source: Internet
Author: User

Apart from Nian, there are a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that is Sui tries to approach them, it'll be driven away by the fairies inside.

Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony.

He would like-to-find a positive integer n not greater than 1018, such that there is exactly k loops in the decimal repre Sentation of N, or determine that such n does not exist.

A loop is a planar area enclosed by lines in the digits ' decimal representation written in Arabic numerals. For example, there are one loop in digit 4, and the other loops in 8 and no loops in 5. Refer to the figure below for all exact forms. Input

The first and only line contains an integer k (1≤k≤106)-the desired number of loops. Output

Output an integer-if no such n exists, output-1; Otherwise output any such n. In the latter case, your output should is a positive decimal integer not exceeding 1018. Examples Input

2
Output
462
Input
6
Output
8080

Test instructions: For a number containing n rings, give the number not more than 1e18,

For example, 3,5,7 contains 0 rings; 8 contains 2 rings; 0,4,6,9 contains 1 rings

Thinking: 888888888888888888 contains 36 rings, which is the largest number of rings in 1e18

If N%2==1 first print 6, then print N/2 8;

N%2==0 straight back print N/2 a 8

#include <bits/stdc++.h>
using namespace std;

int main () {
	int n;
    scanf ("%d", &n);
	if (n>36) printf (" -1\n");
	else{
		int k=n%2;
		if (k) printf ("6");
		for (int i=0;i<n/2;i++)
		printf ("8");
		printf ("\ n");
	}  
	return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.