fork(1) download
  1. // coding in the memory of Legend :)
  2.  
  3.  
  4. //~ mail ID : neernpatel@gmail.com
  5. //~ Author : DrexDelta
  6. //~ codechef : drexdelta , hackerRank : drexdelta , codeforces : drexdelta1
  7. //~ Contact Info : neernpatel@gmail.com
  8.  
  9.  
  10. #include<iostream>
  11. #include <cctype>
  12. #include <cerrno>
  13. #include <cfloat>
  14. #include <ciso646>
  15. #include <climits>
  16. #include <clocale>
  17. #include <cmath>
  18. #include <csetjmp>
  19. #include <csignal>
  20. #include <cstdarg>
  21. #include <cstddef>
  22. #include <cstdio>
  23. #include <cstdlib>
  24. #include <cstring>
  25. #include <ctime>
  26. #include <ccomplex>
  27. #include <cfenv>
  28. #include <cinttypes>
  29. #include <cstdbool>
  30. #include <cstdint>
  31. #include <ctgmath>
  32. #include <cwchar>
  33. #include <cwctype>
  34. #include <algorithm>
  35. #include <bitset>
  36. #include <complex>
  37. #include <deque>
  38. #include <exception>
  39. #include <fstream>
  40. #include <functional>
  41. #include <iomanip>
  42. #include <ios>
  43. #include <iosfwd>
  44. #include <iostream>
  45. #include <istream>
  46. #include <iterator>
  47. #include <limits>
  48. #include <list>
  49. #include <locale>
  50. #include <map>
  51. #include <memory>
  52. #include <new>
  53. #include <numeric>
  54. #include <ostream>
  55. #include <queue>
  56. #include <set>
  57. #include <sstream>
  58. #include <stack>
  59. #include <stdexcept>
  60. #include <streambuf>
  61. #include <string>
  62. #include <typeinfo>
  63. #include <utility>
  64. #include <valarray>
  65. #include <vector>
  66. #include <array>
  67. #include <unordered_map>
  68. #include <unordered_set>
  69.  
  70.  
  71. using namespace std;
  72.  
  73. #define F first
  74. #define S second
  75. #define MP make_pair
  76. #define PB push_back
  77. #define UB upper_bound
  78. #define LB lower_bound
  79. #define ER erase
  80. #define EN end()
  81. #define B begin()
  82. #define I insert
  83. #define OPTIMIZE ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  84. #define int ll
  85. #define endl "\n"
  86. #define CO cout <<
  87. #define CI cin >>
  88. #define NL cout << endl;
  89. #define DBG {int debug ; cin >> debug;}
  90. #define AND &&
  91. #define OR ||
  92. #define XOR ^
  93. #define OFLUSH fflush(stdout);
  94. #define IFLUSH fflush(stdin);
  95. #define LEN(x) ((int)x.length())
  96.  
  97. #define rep(i,x) for(int i = 0 ; i < x ; i++)
  98. #define rep1(i,x) for(int i = 1 ; i <= x ; i++)
  99.  
  100. #define repl(var,start_val,limit_val) for(int var = start_val ; var <= limit_val ; var++)
  101. #define perl(var,start_val,limit_val) for(int var = start_val ; var >= limit_val ; var--)
  102.  
  103. #define y1 qwert
  104. #define y2 trewq
  105. #define x1 asdfg
  106. #define x2 gfdsa
  107.  
  108. typedef long long ll;
  109. typedef pair<int,int> ii;
  110. typedef vector<int> vi;
  111. typedef set<int> si;
  112. typedef multiset<int> msi;
  113. typedef long double ld;
  114.  
  115. const ll MOD = 1e9 + 7;
  116. /////////////////////////
  117. // declaration section //
  118. /////////////////////////
  119.  
  120. string s;
  121. int n , k;
  122. void getInput(){
  123.  
  124. cin >> s;
  125. cin >> k;
  126. n =0;
  127. rep(i,LEN(s)){
  128. if(s[i]=='1'){
  129. n++;
  130. }
  131. n<<=1;
  132. }
  133. cout << n/2 << endl;
  134.  
  135. }
  136.  
  137. int cnt = 0;
  138. bool check(int ones){
  139.  
  140.  
  141. int counts , reps = 0;
  142.  
  143. while(ones != 1){
  144.  
  145. counts = 0;
  146. while(ones != 0){
  147. if(ones&1)counts++;
  148. ones>>=1;
  149. }
  150. ones = counts;
  151. reps++;
  152.  
  153. }
  154.  
  155. cnt = reps;
  156.  
  157. return(reps >= k);
  158.  
  159. }
  160.  
  161. void solve(){
  162. int ans = 0;
  163.  
  164. cout << ans << endl;
  165. repl(i,1,n/2){
  166. if(check(i))ans++ , cout <<i << " is valid " << endl;
  167. }
  168.  
  169. cout << ans << endl;
  170.  
  171. }
  172.  
  173. signed main(){
  174.  
  175. OPTIMIZE
  176. cout << " demo " << endl;
  177. repl(i,1,10){
  178. check(i);
  179. cout << " no of steps to convert " << i << " into " << 1 << " is " << cnt << endl;
  180. }
  181.  
  182. //freopen("in.txt" , "r" , stdin) ;
  183. //freopen("out.txt" , "w" , stdout) ;
  184.  
  185. int t=1;
  186. //cin >> t;
  187. while(t--)
  188. getInput() , solve();
  189.  
  190. return 0;
  191.  
  192. }
  193.  
Success #stdin #stdout 0s 4564KB
stdin
111111011
2
stdout
 demo 
 no of steps to convert 1 into 1 is 0
 no of steps to convert 2 into 1 is 1
 no of steps to convert 3 into 1 is 2
 no of steps to convert 4 into 1 is 1
 no of steps to convert 5 into 1 is 2
 no of steps to convert 6 into 1 is 2
 no of steps to convert 7 into 1 is 3
 no of steps to convert 8 into 1 is 1
 no of steps to convert 9 into 1 is 2
 no of steps to convert 10 into 1 is 2
507
0
3 is valid 
5 is valid 
6 is valid 
7 is valid 
9 is valid 
10 is valid 
11 is valid 
12 is valid 
13 is valid 
14 is valid 
15 is valid 
17 is valid 
18 is valid 
19 is valid 
20 is valid 
21 is valid 
22 is valid 
23 is valid 
24 is valid 
25 is valid 
26 is valid 
27 is valid 
28 is valid 
29 is valid 
30 is valid 
31 is valid 
33 is valid 
34 is valid 
35 is valid 
36 is valid 
37 is valid 
38 is valid 
39 is valid 
40 is valid 
41 is valid 
42 is valid 
43 is valid 
44 is valid 
45 is valid 
46 is valid 
47 is valid 
48 is valid 
49 is valid 
50 is valid 
51 is valid 
52 is valid 
53 is valid 
54 is valid 
55 is valid 
56 is valid 
57 is valid 
58 is valid 
59 is valid 
60 is valid 
61 is valid 
62 is valid 
63 is valid 
65 is valid 
66 is valid 
67 is valid 
68 is valid 
69 is valid 
70 is valid 
71 is valid 
72 is valid 
73 is valid 
74 is valid 
75 is valid 
76 is valid 
77 is valid 
78 is valid 
79 is valid 
80 is valid 
81 is valid 
82 is valid 
83 is valid 
84 is valid 
85 is valid 
86 is valid 
87 is valid 
88 is valid 
89 is valid 
90 is valid 
91 is valid 
92 is valid 
93 is valid 
94 is valid 
95 is valid 
96 is valid 
97 is valid 
98 is valid 
99 is valid 
100 is valid 
101 is valid 
102 is valid 
103 is valid 
104 is valid 
105 is valid 
106 is valid 
107 is valid 
108 is valid 
109 is valid 
110 is valid 
111 is valid 
112 is valid 
113 is valid 
114 is valid 
115 is valid 
116 is valid 
117 is valid 
118 is valid 
119 is valid 
120 is valid 
121 is valid 
122 is valid 
123 is valid 
124 is valid 
125 is valid 
126 is valid 
127 is valid 
129 is valid 
130 is valid 
131 is valid 
132 is valid 
133 is valid 
134 is valid 
135 is valid 
136 is valid 
137 is valid 
138 is valid 
139 is valid 
140 is valid 
141 is valid 
142 is valid 
143 is valid 
144 is valid 
145 is valid 
146 is valid 
147 is valid 
148 is valid 
149 is valid 
150 is valid 
151 is valid 
152 is valid 
153 is valid 
154 is valid 
155 is valid 
156 is valid 
157 is valid 
158 is valid 
159 is valid 
160 is valid 
161 is valid 
162 is valid 
163 is valid 
164 is valid 
165 is valid 
166 is valid 
167 is valid 
168 is valid 
169 is valid 
170 is valid 
171 is valid 
172 is valid 
173 is valid 
174 is valid 
175 is valid 
176 is valid 
177 is valid 
178 is valid 
179 is valid 
180 is valid 
181 is valid 
182 is valid 
183 is valid 
184 is valid 
185 is valid 
186 is valid 
187 is valid 
188 is valid 
189 is valid 
190 is valid 
191 is valid 
192 is valid 
193 is valid 
194 is valid 
195 is valid 
196 is valid 
197 is valid 
198 is valid 
199 is valid 
200 is valid 
201 is valid 
202 is valid 
203 is valid 
204 is valid 
205 is valid 
206 is valid 
207 is valid 
208 is valid 
209 is valid 
210 is valid 
211 is valid 
212 is valid 
213 is valid 
214 is valid 
215 is valid 
216 is valid 
217 is valid 
218 is valid 
219 is valid 
220 is valid 
221 is valid 
222 is valid 
223 is valid 
224 is valid 
225 is valid 
226 is valid 
227 is valid 
228 is valid 
229 is valid 
230 is valid 
231 is valid 
232 is valid 
233 is valid 
234 is valid 
235 is valid 
236 is valid 
237 is valid 
238 is valid 
239 is valid 
240 is valid 
241 is valid 
242 is valid 
243 is valid 
244 is valid 
245 is valid 
246 is valid 
247 is valid 
248 is valid 
249 is valid 
250 is valid 
251 is valid 
252 is valid 
253 is valid 
254 is valid 
255 is valid 
257 is valid 
258 is valid 
259 is valid 
260 is valid 
261 is valid 
262 is valid 
263 is valid 
264 is valid 
265 is valid 
266 is valid 
267 is valid 
268 is valid 
269 is valid 
270 is valid 
271 is valid 
272 is valid 
273 is valid 
274 is valid 
275 is valid 
276 is valid 
277 is valid 
278 is valid 
279 is valid 
280 is valid 
281 is valid 
282 is valid 
283 is valid 
284 is valid 
285 is valid 
286 is valid 
287 is valid 
288 is valid 
289 is valid 
290 is valid 
291 is valid 
292 is valid 
293 is valid 
294 is valid 
295 is valid 
296 is valid 
297 is valid 
298 is valid 
299 is valid 
300 is valid 
301 is valid 
302 is valid 
303 is valid 
304 is valid 
305 is valid 
306 is valid 
307 is valid 
308 is valid 
309 is valid 
310 is valid 
311 is valid 
312 is valid 
313 is valid 
314 is valid 
315 is valid 
316 is valid 
317 is valid 
318 is valid 
319 is valid 
320 is valid 
321 is valid 
322 is valid 
323 is valid 
324 is valid 
325 is valid 
326 is valid 
327 is valid 
328 is valid 
329 is valid 
330 is valid 
331 is valid 
332 is valid 
333 is valid 
334 is valid 
335 is valid 
336 is valid 
337 is valid 
338 is valid 
339 is valid 
340 is valid 
341 is valid 
342 is valid 
343 is valid 
344 is valid 
345 is valid 
346 is valid 
347 is valid 
348 is valid 
349 is valid 
350 is valid 
351 is valid 
352 is valid 
353 is valid 
354 is valid 
355 is valid 
356 is valid 
357 is valid 
358 is valid 
359 is valid 
360 is valid 
361 is valid 
362 is valid 
363 is valid 
364 is valid 
365 is valid 
366 is valid 
367 is valid 
368 is valid 
369 is valid 
370 is valid 
371 is valid 
372 is valid 
373 is valid 
374 is valid 
375 is valid 
376 is valid 
377 is valid 
378 is valid 
379 is valid 
380 is valid 
381 is valid 
382 is valid 
383 is valid 
384 is valid 
385 is valid 
386 is valid 
387 is valid 
388 is valid 
389 is valid 
390 is valid 
391 is valid 
392 is valid 
393 is valid 
394 is valid 
395 is valid 
396 is valid 
397 is valid 
398 is valid 
399 is valid 
400 is valid 
401 is valid 
402 is valid 
403 is valid 
404 is valid 
405 is valid 
406 is valid 
407 is valid 
408 is valid 
409 is valid 
410 is valid 
411 is valid 
412 is valid 
413 is valid 
414 is valid 
415 is valid 
416 is valid 
417 is valid 
418 is valid 
419 is valid 
420 is valid 
421 is valid 
422 is valid 
423 is valid 
424 is valid 
425 is valid 
426 is valid 
427 is valid 
428 is valid 
429 is valid 
430 is valid 
431 is valid 
432 is valid 
433 is valid 
434 is valid 
435 is valid 
436 is valid 
437 is valid 
438 is valid 
439 is valid 
440 is valid 
441 is valid 
442 is valid 
443 is valid 
444 is valid 
445 is valid 
446 is valid 
447 is valid 
448 is valid 
449 is valid 
450 is valid 
451 is valid 
452 is valid 
453 is valid 
454 is valid 
455 is valid 
456 is valid 
457 is valid 
458 is valid 
459 is valid 
460 is valid 
461 is valid 
462 is valid 
463 is valid 
464 is valid 
465 is valid 
466 is valid 
467 is valid 
468 is valid 
469 is valid 
470 is valid 
471 is valid 
472 is valid 
473 is valid 
474 is valid 
475 is valid 
476 is valid 
477 is valid 
478 is valid 
479 is valid 
480 is valid 
481 is valid 
482 is valid 
483 is valid 
484 is valid 
485 is valid 
486 is valid 
487 is valid 
488 is valid 
489 is valid 
490 is valid 
491 is valid 
492 is valid 
493 is valid 
494 is valid 
495 is valid 
496 is valid 
497 is valid 
498 is valid 
499 is valid 
500 is valid 
501 is valid 
502 is valid 
503 is valid 
504 is valid 
505 is valid 
506 is valid 
507 is valid 
498