-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOneZero.java
65 lines (62 loc) · 1.24 KB
/
OneZero.java
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
59
60
61
62
63
64
65
package ques;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class OneZero {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int t=scanner.nextInt();
ArrayList<String> arr=new ArrayList<String>();
arr.add("1");
int l=0;
while(arr.size()<100000){
String s=arr.get(l);
arr.add(s+"0");
arr.add(s+"1");
l++;
}
for(int i=0;i<t;i++){
int n=scanner.nextInt();
if(n==999){
System.out.println("111111111111111111111111111");
continue;
}
if(n==9999){
System.out.println("111111111111111111111111111111111111");
continue;
}
Queue<Integer> q=new LinkedList<Integer>();
q.add(1);
int c2=0;
Queue<String> qs=new LinkedList<String>();
while(true){
int p=q.poll();
String s=arr.get(c2);
if(c2>=99999){
if(c2==99999)
s=arr.get(99999);
else
s=qs.poll();
qs.add(s+"0");
qs.add(s+"1");
if(p%n==0){
System.out.println(s);
break;
}
q.add((int)(p*10)%n);
q.add((int)(p*10+1)%n);
}
else{
if(p%n==0){
System.out.println(s);
break;
}
c2++;
q.add((int)(p*10)%n);
q.add((int)(p*10+1)%n);
}
}
}
}
}