Apart from Nian, there is 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 when Sui tries to approach them, it will 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 are exactly k loops in the decimal representation 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 is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms.
The first and only line contains an integer k (1 ≤ k ≤ 106) — the desired number of loops.
Output an integer — if no such n exists, output -1; otherwise output any such n. In the latter case, your output should be a positive decimal integer not exceeding 1018.
2
462
6
8080
题意:求一个含有n个环的数字,给数字不超过1e18,
如 1,2 ,3,5,7 含有0个环;8含有2个环;0,4,6,9含有1个环
思考:888888888888888888 含有36个环,为在1e18内含环最多的数字
如果n%2==1 先打印6 ,后面打印n/2个8;
n%2==0 直接后面打印n/2个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;
}