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.
a Decent number has The following properties:
- 3, 5, or both as its digits. No other digit is allowed.
- Number of times 3 appears is divisible by 5.
- 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