[2018-4-8]BNUZ套题比赛div2 E - A Prosperous Lot 【补题】

题目链接:CodeForces - 934B 

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 ofn, or determine that such n does not exist.

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 apositive decimal integer not exceeding 1018.

Examples
Input
2
Output
462
Input
6
Output
8080


其实这道题就是 看数字有几个圈,比如0 4 6 9  有一个圈 8 有两个圈,输出结果不能超过10^18也就是不能有超过36个圈

超过就要输出1;

#include <stdio.h>

int main () {
	int n;
	scanf("%d",&n);
	int a,b;
	a = n / 2;
	b = n % 2;
	if(n <= 36) {
		if(n == 0) {
			printf("1");
		} else {
			for(int i = 0; i < a; i++) {
				printf("8");
			}
			for(int i = 0; i < b; i++) {
				printf("9");
			}
		}
	}else{
		printf("-1");
	}

	printf("\n");
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值