A Prosperous Lot

本文介绍了一个有趣的数学问题:如何找到一个不超过10^18的正整数n,使得其十进制表示中恰好包含k个环。环是指阿拉伯数字书写形式中封闭的平面区域,例如数字4有一个环,而数字8有两个环。文章提供了一种算法解决方案。

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
Copy
2
Output
462
Input
Copy
6
Output
8080

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

// a positive integer n not greater than 10^18
//所以换最多18*2个

int main()
{
    int k;
    int x=8,y=9;
    cin>>k;
    if(k>36)
        printf("-1\n");
    else
    {
        if(k%2)
        {
            cout<<y;
        }
        k/=2;
        while(k--)
            cout<<x;

    }
    return 0;
}


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值