Sherlock and the Beast

Source: Internet
Author: User

Problem Statement

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

This afternoon, Sherlock received a note from Moriarty, saying that he had infected ' the Beast ' with a virus. Moreover, the note had the numbern  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. 3, 5, 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 would contain an integer < Span id= "Mathjax-element-62-frame" class= "Mathjax" >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 the He is wrong and Print  − 1 .

Constraints
1≤T≤
1≤N≤100000

Sample Input

413511

Sample Output

-15553333355555533333

explanation
ForN=1 , there is no such number.
ForN=3 ,555is the only possible number.
ForN=5, 33333 is the only possible number.
For N=One, 55555533333 and all permutations of these digits is valid numb ERs Among them, the given number is the largest one.

#include <cmath>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>#include<typeinfo>using namespacestd;intMain () {intLoops =0; CIN>>loops;  for(intI=0; i<loops; i++){        intLength =0; CIN>>length; if(length%3==0) {            stringDig (length,'5'); cout<<dig<<Endl; }        Else if(length%3==1)            if(length<Ten) cout<<-1<<Endl; Else {                stringFive (length-Ten,'5'); stringThree (Ten,'3'); cout<<five+three<<Endl; }        Else            if(length<5) cout<<-1<<Endl; Else {                stringFive (length-5,'5'); stringThree (5,'3'); cout<<five+three<<Endl; }    }    return 0;}

Sherlock and the Beast

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.