B. A Prosperous Lot
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

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 be a positive decimal integer not exceeding 1018.

Examples
input
2
output
462
input
6
output
8080

题意:输入一个数k来表示一串数里面包含的封闭部分(如:8有2个,4、6、9分别有1个,5没有……),输出一组有k部分封闭的数(正整数),输出不超过 1018

/*36/2=18,所以输出不为-1的k的最大值为36
因为8有两个部分封闭,所以当k是奇数的时候可以用有一个封闭部分的数(如4,6,9)来补上。
*/
#include<bits/stdc++.h>
int main()
{
int k;
scanf("%d",&k);
if(k>36) printf("-1");
else
{
if(k%2==0)//判断奇偶
{
for(int i=0;i<k/2;i++) printf("8");
printf("\n");
}
else
{
for(int i=0;i<k/2;i++) printf("8");
printf("4\n");//也可以用6,或9;但不能用0,因为k=1的时候输出是0,不是正整数
}//如果用0的话,需要在前面再加一个判断语句
}
return 0;
}

Codeforces Round #462 (Div. 2) B-A Prosperous Lot的更多相关文章

  1. Codeforces Round #462 (Div. 2), problem: (C) A Twisty Movement (求可以转一次区间的不递增子序列元素只有1,2)

    题目意思: 给长度为n(n<=2000)的数字串,数字只能为1或者2,可以将其中一段区间[l,r]翻转,求翻转后的最长非递减子序列长度. 题解:求出1的前缀和,2的后缀和,以及区间[i,j]的最 ...

  2. Codeforces Round #462 (Div. 2) C DP

    C. A Twisty Movement time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #462 (Div. 2)

    这是我打的第三场cf,个人的表现还是有点不成熟.暴露出了我的一些问题. 先打开A题,大概3min看懂题意+一小会儿的思考后开始码代码.一开始想着贪心地只取两个端点的值就好了,正准备交的时候回想起上次A ...

  4. Codeforces Round #462 (Div. 2) D. A Determined Cleanup

    D. A Determined Cleanup time limit per test1 second memory limit per test256 megabytes Problem Descr ...

  5. Codeforces Round #462 (Div. 2) C. A Twisty Movement

    C. A Twisty Movement time limit per test1 second memory limit per test256 megabytes Problem Descript ...

  6. Codeforces Round #462 (Div. 2) A Compatible Pair

    A. A Compatible Pair time limit per test1 second memory limit per test256 megabytes Problem Descript ...

  7. 【Codeforces Round #462 (Div. 1) B】A Determined Cleanup

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 设\(设f(x)=a_d*x^{d}+a_{d-1}*x^{d-1}+...+a_1*x+a_0\) 用它去除x+k 用多项式除法除 ...

  8. 【Codeforces Round #462 (Div. 1) A】 A Twisty Movement

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] ans初值值为a[1..n]中1的个数. 接下来考虑以2为结尾的最长上升子序列的个数. 枚举中间点i. 计算1..i-1中1的个数c ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. Struts2 简介图

    Struts2官方提供的,strus2的内部工作机制图解.

  2. Service Account和其secrets 作用和场景,看了不亏。。

    Service Account概念的引入是基于这样的使用场景: 运行在pod里的进程需要调用Kubernetes API以及非Kubernetes API的其它服务.Service Account它并 ...

  3. HDU-1272 小希的迷宫 (并查集、判断图是否为树)

    Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就 ...

  4. POJ-1511 Invitation Cards (双向单源最短路)

    Description In the age of television, not many people attend theater performances. Antique Comedians ...

  5. iosFQ教程

    https://www.youtube.com/watch?v=B8Vu3Xrivsc + https://sobaigu.com/how-to-use-shadowrocket-ios.html

  6. 使用GAN 进行异常检测——anoGAN,TODO,待用于安全分析实验

    先说实验成功的代码: git clone https://github.com/tkwoo/anogan-keras.git mkdir weights python main.py --mode t ...

  7. web移动端生产环境调试

    如果是开发环境,比较容易: 最笨的方法是手机开QQ电脑开QQ把做好的页面传给手机QQ直接打开.. 参考: http://blog.allenm.me/2014/05/mobile-web-debug- ...

  8. PHP:第一章——PHP中的算术运算符/递增、递减运算符/赋值运算符

    算术运算符 //$a=10; $b=5; //取反: //echo -$a;//输出:-10: //加法: //echo $a+$b;//输出:15 //减法: //echo $a-$b;//输出:5 ...

  9. json 与字符串相互转换,

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...

  10. 跟我一起学习ASP.NET 4.5 MVC4.0(四)

    前几个文章中介绍了一些关于MVC4.0的东东,今天我们来看一下登陆验证,也可以说是权限验证,即AuthorizeAttribute.这个可以使用在控制器Controller上,也可以使用在Action ...