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. input聚焦后光标移动至末尾

    var valSrc=obj.val();obj.val(“”).focus().val(valSrc);

  2. Machine Learning 资料

    Awesome系列 Awesome Machine Learning Awesome Deep Learning Awesome TensorFlow Awesome TensorFlow Imple ...

  3. Java读取xml

    首先将xml的格式展示出来,如下 <?xml version="1.0"?> <configuration> <connectionStrings n ...

  4. 雷林鹏分享:Ruby 类案例

    Ruby 类案例 下面将创建一个名为 Customer 的 Ruby 类,您将声明两个方法: display_details:该方法用于显示客户的详细信息. total_no_of_customers ...

  5. 新概念 Lesson 4 Are you a teacher

    打招呼用语: Good morning, Good afternoon,Good evening Nice to meet you. How do you do? She is French. 她是法 ...

  6. LeetCode--176--第二高的薪水

    问题描述: 编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . +----+--------+ | Id | Salary | +----+--------+ | 1 ...

  7. 20161212xlVBA文本文件多列合并

    Sub NextSeven_CodeFrame() '应用程序设置 Application.ScreenUpdating = False Application.DisplayAlerts = Fal ...

  8. 玲珑杯 ACM热身赛 #2.5 A 记忆化搜索+瞎搞

    #include <cstdio> #include <vector> #include <iostream> #include <algorithm> ...

  9. Leetcode 113

    /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...

  10. 【转】C# 生成二维码并且在中间加Logo(图片合并)

    public class QRCodeHelper { public static Bitmap GetThumbnail(Bitmap b, int destHeight, int destWidt ...