-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSherlockAndTheBeast.java
More file actions
43 lines (38 loc) · 1.15 KB
/
SherlockAndTheBeast.java
File metadata and controls
43 lines (38 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.io.*;
import java.util.*;
public class SherlockAndTheBeast
{
public static String createDescentNumber(int fives, int threes)
{
String []numArray = new String[fives+threes];
StringBuilder numString = new StringBuilder();
for(int i = 0;i<fives;i++){
numString.append("5");
}
for(int i = 0;i<threes;i++){
numString.append("3");
}
return numString.toString();
}
public static String getDescentNumber(int n)
{
String num = "-1";
for(int i = n;i >= 0; i--){
if((i)%3 == 0 && (((n-i))%5) == 0){
num = createDescentNumber(i,n-i);
break;
}else if ((i)%5 == 0 && (((n-i))%3) == 0){
num = createDescentNumber(i,n-i);
}
}
return num;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int numTestCases = Integer.parseInt(sc.nextLine());
for(int i = 0;i < numTestCases; i++){
int n = sc.nextInt();
System.out.println(getDescentNumber(n));
}
}
}