-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSherlock_And_The_Beast.java
More file actions
58 lines (57 loc) · 917 Bytes
/
Copy pathSherlock_And_The_Beast.java
File metadata and controls
58 lines (57 loc) · 917 Bytes
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package practicetime;
import java.util.*;
public class Sherlock_And_The_Beast
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++)
{
long n=sc.nextLong();
if(n<3 || n==4 || n==7)
{
System.out.print("-1");
}
else
{
if(n%3==0)
{
for(int j=1;j<=n;j++)
{
System.out.print("5");
}
}
else
{
long x=0,y=0;
long m=n;
long k=1;
long r=n%3;
//int r1=n%5;
while(k<m)
{
long b=5*k;
long z=b-r;
if(z%3==0)
{
x=(n-r)-z;
y=n-x;
break;
}
k++;
}
for(int j=1;j<=x;j++)
{
System.out.print("5");
}
for(int j=1;j<=y;j++)
{
System.out.print("3");
}
}
}
System.out.println();
}
}
}