Sherlock and The Beast

Problem Statement

Sherlock Holmes is getting paranoid about Professor Moriarty, his arch-enemy. All his efforts to subdue Moriarty have been in vain. These days Sherlock is working on a problem with Dr. Watson. Watson mentioned that the CIA has been facing weird problems with their supercomputer, 'The Beast', recently.

This afternoon, Sherlock received a note from Moriarty, saying that he has infected 'The Beast' with a virus. Moreover, the note had the number N printed on it. After doing some calculations, Sherlock figured out that the key to remove the virus is the largest Decent Number having N digits.

Decent Number has the following properties:

  1. 35, or both as its digits. No other digit is allowed.
  2. Number of times 3 appears is divisible by 5.
  3. Number of times 5 appears is divisible by 3.

Meanwhile, the counter to the destruction of 'The Beast' is running very fast. Can you save 'The Beast', and find the key before Sherlock?

Input Format
The 1st line will contain an integer T, the number of test cases. This is followed by T lines, each containing an integer N. i.e. the number of digits in the number. 

Output Format
Largest Decent Number having N digits. If no such number exists, tell Sherlock that he is wrong and print 1.

Constraints
1T20
1N100000

Sample Input

4
1
3
5
11

Sample Output

-1
555
33333
55555533333

Explanation
For N=1, there is no such number.
For N=3555 is the only possible number.
For N=533333 is the only possible number.
For N=1155555533333 and all permutations of these digits are valid numbers; among them, the given number is the largest one.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <typeinfo>
using namespace std;

int main() {
    int loops = 0;
    cin>>loops;
    for(int i=0; i<loops; i++){
        int length = 0;
        cin>>length;
        if(length%3==0) {
            string dig(length,'5');
            cout<<dig<<endl;
        }
        else if(length%3==1)
            if(length<10) cout<<-1<<endl;
            else {
                string five(length-10, '5');
                string three(10,'3');
                cout<<five+three<<endl;
            }
        else
            if(length<5) cout<<-1<<endl;
            else {
                string five(length-5, '5');
                string three(5,'3');
                cout<<five+three<<endl;
            }
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/XingyingLiu/p/4948895.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值