934B A Prosperous Lot

B. A Prosperous Lot
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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

题意:banabn放压岁钱在袋子里,输入k,代表需要的压岁钱里面的数字要组成的环(0,4,6,9一个环,8两个环,其余数字没有环),如果组成出来的数字能够满足有就输出这个数,没有的话,输出-1.注意输出的数字范围不能超过10^18,并且是正整数
题解:拼凑  我最开始思路都是对的,方法也没问题,代码也没什么问题,就是没有注意正整数,晚上比赛的时候一直wa7组,找不来问题,后面完了,在看到正整数。。。有时候真的....哎。..回归正题,我们肯定从两个环开始选数字,然后不够在来拼凑一个环的任意数字,0除开。不然一个环0,不是正整数,我就是wa 这里。需要技巧的是:10^18有18位,所以我们可以拼凑18个8的数字,888888888888888888像这个样有36个环,也就是最多的,8*10^17小于10^18,大于36个环就没有了,超出范围,输出-1,其余的情况如果是偶数,我们就输出k/2个8,奇数的话在多输出一个环的数字不要带0这个数字,4,6,9任选一个。
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    while(cin>>k)
    {
        if(k>36)
            puts("-1");
        else
        {
            for(int i=0; i<k/2; i++)
                cout<<"8";
            if(k%2)
                cout<<"6";
                printf("\n");
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

落凡尘.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值