File tree 1 file changed +48
-0
lines changed
C Programs/C Programs - 3 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < cstdio>
2
+ #include < iostream>
3
+ #include < queue>
4
+
5
+ using namespace std ;
6
+
7
+ void solve ()
8
+ {
9
+ int n;
10
+ scanf (" %d" , &n);
11
+
12
+ queue <string> number;
13
+ queue <int > remainder ;
14
+
15
+ number.push (" 1" );
16
+ remainder .push (1 %n);
17
+
18
+ while (true )
19
+ {
20
+ int current_remainder = remainder .front ();
21
+ string current_number = number.front ();
22
+
23
+ if (current_remainder == 0 )
24
+ {
25
+ cout << current_number << ' \n ' ;
26
+ return ;
27
+ }
28
+
29
+ number.push (current_number + " 0" );
30
+ number.push (current_number + " 1" );
31
+ number.pop ();
32
+
33
+ remainder .push ((current_remainder*10 )%n);
34
+ remainder .push ((current_remainder*10 + 1 )%n);
35
+ remainder .pop ();
36
+ }
37
+ }
38
+
39
+ int main ()
40
+ {
41
+ int no_of_test_cases;
42
+ scanf (" %d" , &no_of_test_cases);
43
+
44
+ while (no_of_test_cases--)
45
+ solve ();
46
+
47
+ return 0 ;
48
+ }
You can’t perform that action at this time.
0 commit comments