What's the minimum number of $2$s needed to write a positive integer?

I've been silly; we don't need to work with iterated logarithms. We can get a logarithmic upper bound by using the binary expansion slightly more cleverly. Namely, we can always write $n = 2n' + \left( n \bmod 2 \right)$, so either $2k = 2(k)$ or $2k+1 = 2(k) + \frac 22$, which gives

$$f(2k) \le f(k) + 1$$ $$f(2k+1) \le f(k) + 3.$$

Iterating these bounds gives

$$\boxed{ f(n) \le 3 \lceil \log_2 n \rceil - 1 \approx 4.32 \log n }$$

which corresponds to writing $n$ as $d_0 + 2(d_1 + 2(d_2 + \dots)))$ where $d_i$ are the binary digits of $n$. This uses only addition, multiplication and division and lots of optimizations are possible. This gives $f(14885392687) \le 3 \cdot 33 + 2 = 101$ which is at least within a factor of $3$ of the explicit result.

As an example of a possible optimization, we can improve the bound by working in base $22$, which gives

$$f(n) \le \left( 2 + g(21) \right) \lceil \log_{22} n \rceil.$$

My computations give $g(21) \le 5$ (the maximum value of $5$ is attained for $n = 7, 15, 17, 19$, at least if I'm not mistaken), so

$$\boxed{ f(n) \le 7 \lceil \log_{22} n \rceil \approx 2.26 \log n }$$

which is almost twice as good! This gives $f(14885392687) \le 56$ which still doesn't quite match the explicit result. Using subtraction we can replace $g(21)$ above by $g(10)$ but since $g(10) = 5$ also this doesn't actually help in this case.

We can write down a logarithmic lower bound on $g$ by writing down an exponential upper bound on the number $N(k)$ of possible expressions involving $k$ twos. (At least one number between $1$ and $N(k)+1$ can't be represented using $k$ twos, so $g(N(k) + 1) \ge k+1$.) We can do a more precise count than the following but this will suffice. An expression involving $k$ twos involves at most $k-1$ operations and at most $k-1$ pairs of parentheses, so altogether is a string of at most $4k-3$ symbols each of which can take the values $2, (, ), +, -, \times, \div$, or exponentiation (note that we don't need a symbol for concatenation). This gives the crude bound $N(k) \le 7^{4k-3}$, so

$$g(7^{4k-3} + 1) \ge k + 1$$

which after a bit of massaging gives

$$\boxed{ g(n) \ge \frac{\lceil \log_7 n \rceil + 3}{4} \approx 0.128 \log n }.$$

This gives $g(14885392687) \ge 4$ which is quite bad! Can anyone do substantially better, possibly after disallowing some of the operations? A lower bound given only addition, multiplication, and exponentiation would already be quite interesting, I think.


Just observation.

For given $d$ ($d\ge 2$) consider "milestone values" $k(d)$: the smallest number, which requires $d$ $\;2$s
(such that all numbers below $k(d)$ require $<d$ $\;2$s).

Example:
for $d=5$ all numbers below $7$ could be expressed via $<5$ $\;2$s, but $7$ requires $5$ $\;2$s: $$ 7 = 2+2+2+2/2 = 2^2+2+2/2 = 2\times 2\times 2 - 2/2. $$ Therefore, $k(5)=7$.

According to my computations (checking all numbers below $150\;000$), first values for $k(d)$ are:

\begin{array}{|c|c|l|} \hline d & k(d) & example \; of \; expression \\ \hline 2 & 1 & 1=2/2 \\ 3 & 3 & 3 = 2+2/2 \\ 4 & 5 & 5 = 2+2+2/2 \\ 5 & 7 & 7 = 2+2+2+2/2 \\ 6 & 27 & 27 = 3^3 = (2+2/2)^{2+2/2} \\ 7 & 29 & 29 = 22/2 + 22-2-2 \\ 8 & 149 & 149 = (4^4-2)/2+22 = ((2+2)^{2+2}-2)/2+22 \\ 9 & 271 & 271 = 222 + (22+2)\times 2 + 2/2 \\ 10 & 691 & 691 = (22+2)^2 + 222/2 + 2+2 \\ 11 & 1381 & 1381 = (222+2)\times (2+2) + 22^2 + 2/2 \\ 12 & 3493 & 3493 = (222-2-2) \times 2^{2+2} + 2+2+2/2 \\ 13 & 9907 & 9907 = 484\times 20 + 227 = 22^2\times (22-2) + 222 + 2+2+2/2 \\ 14 & 34\:093 & 34\:093 = 2^{16}/2 + 11^3-6 = 2^{(2+2)^2}/2 + (22/2)^{2+2/2}-2-2-2 \\ 15 & 120\:347 & 120\:347 = (222-2/2)^2 + 222^2+22222 \\ 16 & 305\:421 & 305\:421 = \bigl(((22-2) \times (2+2)^2 - 2/2)^2 + 2\times 22 + 2\bigr) \times (2 + 2/2) \\ ... & ... & ... \end{array}

We can observe that for $d>12$ $\;\;$ $\log_2 k(d) > d$, which (probably) can promise that for large enough $n$ one can expect estimation $$ f(n) \le \log_2 n. $$


To know about such decomposition up to number $n$, I create $3$ arrays:
f[n], o1[n], o2[n].
f[n] - keeps the number of $2$s in the shortest decomposition of the $n$;
o1[n] - for keeping of $1$st operand;
o2[n] - for keeping of $2$nd operand.
all the arrays is filled initially by $0$;
and setting manually f[2]=1, o1[2]=2, o2[2]=0.

After that, I loop through $a,b$, where $1 \le a \le b \le n$,
calculate all possible values
$c=a+b$,
$c=b-a$,
$c=b/a$ (if integer),
$c=a*b$ (if not too large),
$c=a^b$ (if not too large),
$c=b^a$ (if not too large).
If calculated value $c$ is new or requires less $2$s than existing one, then I change corresponding array values f[c], o1[c], o2[c].

And repeat this loop while it provides at least one improvement.

Then, we can be more or less confident about decompositions in the range [1 .. n/2].


And here are first few hundreds of these arrays:

n f(n) o1(n) o2(n)
------------------
1   2   2   2
2   1   2   -
3   3   2   1
4   2   2   2
5   4   3   2
6   3   4   2
7   5   4   3
8   3   4   2
9   4   3   2
10  4   8   2
11  3   22  2
12  4   6   2
13  4   11  2
14  4   16  2
15  5   11  4
16  3   4   2
17  5   16  1
18  4   16  2
19  5   20  1
20  3   22  2
21  4   22  1
22  2   22  -
23  4   22  1
24  3   22  2
25  5   5   2
26  4   22  4
27  6   3   3
28  5   14  2
29  7   16  13
30  5   22  8
31  6   20  11
32  4   16  2
33  5   22  11
34  5   32  2
35  6   22  13
36  4   6   2
37  6   36  1
38  5   22  16
39  6   40  1
40  4   20  2
41  6   40  1
42  4   44  2
43  5   44  1
44  3   22  2
45  5   44  1
46  4   44  2
47  6   44  3
48  4   24  2
49  6   7   2
50  5   48  2
51  7   40  11
52  5   26  2
53  7   42  11
54  6   32  22
55  6   44  11
56  6   14  4
57  7   44  13
58  6   36  22
59  7   48  11
60  6   20  3
61  7   62  1
62  5   64  2
63  6   64  1
64  4   6   2
65  6   64  1
66  5   22  3
67  7   44  23
68  6   34  2
69  7   23  3
70  6   48  22
71  7   72  1
72  5   36  2
73  7   72  1
74  6   72  2
75  7   64  11
76  6   38  2
77  7   79  2
78  6   80  2
79  6   81  2
80  5   20  4
81  5   4   3
82  6   80  2
83  6   81  2
84  5   42  2
85  7   81  4
86  5   88  2
87  6   88  1
88  4   22  4
89  6   88  1
90  5   88  2
91  7   88  3
92  5   46  2
93  7   92  1
94  6   92  2
95  7   96  1
96  5   24  4
97  7   96  1
98  6   96  2
99  6   121 22
100 5   10  2
101 6   2222    22
102 6   100 2
103 7   81  22
104 6   26  4
105 7   107 2
106 7   84  22
107 6   109 2
108 6   110 2
109 5   111 2
110 5   220 2
111 4   222 2
112 5   224 2
113 5   111 2
114 6   112 2
115 6   111 4
116 7   58  2
117 6   119 2
118 7   96  22
119 5   121 2
120 6   20  6
121 4   11  2
122 6   121 1
123 5   121 2
124 6   62  2
125 6   121 4
126 6   128 2
127 6   254 2
128 5   64  2
129 6   258 2
130 6   128 2
131 7   109 22
132 5   22  6
133 6   111 22
134 6   132 2
135 7   111 24
136 7   34  4
137 7   121 16
138 7   23  6
139 7   278 2
140 7   70  2
141 7   119 22
142 6   144 2
143 6   121 22
144 5   12  2
145 7   121 24
146 6   144 2
147 7   169 22
148 7   74  2
149 8   127 22
150 7   128 22
151 8   111 40
152 7   38  4
153 8   109 44
154 7   14  11
155 7   111 44
156 7   26  6
157 8   111 46
158 7   79  2
159 8   111 48
160 6   20  8
161 7   322 2
162 6   81  2
163 7   326 2
164 7   82  2
165 7   121 44
166 7   83  2
167 6   169 2
168 6   42  4
169 5   13  2
170 7   168 2
171 6   169 2
172 6   86  2
173 7   169 4
174 6   176 2
175 7   176 1
176 5   22  8
177 7   176 1
178 6   176 2
179 8   176 3
180 6   90  2
181 8   180 1
182 7   180 2
183 8   184 1
184 6   46  4
185 8   121 64
186 7   184 2
187 8   17  11
188 7   94  2
189 7   378 2
190 7   192 2
191 7   169 22
192 6   24  8
193 8   169 24
194 6   196 2
195 7   196 1
196 5   14  2
197 7   196 1
198 6   22  9
199 6   398 2
200 5   222 22
201 6   402 2
202 6   200 2
203 7   201 2
204 7   102 2
205 8   201 4
206 6   222 16
207 8   23  9
208 7   16  13
209 7   211 2
210 7   222 12
211 6   222 11
212 7   214 2
213 7   211 2
214 6   222 8
215 8   211 4
216 6   6   3
217 7   218 1
218 5   220 2
219 6   220 1
220 4   222 2
221 5   222 1
222 3   222 -
223 5   222 1
224 4   222 2
225 6   15  2
226 5   222 4
227 7   222 5
228 6   222 6
229 7   231 2
230 6   222 8
231 6   462 2
232 7   222 10
233 6   222 11
234 6   256 22
235 7   222 13
236 7   220 16
237 7   239 2
238 6   119 2
239 6   241 2
240 5   242 2
241 5   482 2
242 4   484 2
243 5   486 2
244 5   222 22
245 6   243 2
246 6   123 2
247 7   243 4
248 7   62  4
249 8   241 8
250 7   125 2
251 7   253 2
252 6   254 2
253 6   506 2
254 5   256 2
255 6   256 1
256 4   4   4
257 6   256 1
258 5   256 2
259 7   256 3
260 6   256 4
261 8   239 22
262 6   484 222
263 7   241 22
264 6   22  12
265 7   243 22
266 6   222 44
267 7   256 11
268 7   134 2
269 8   256 13
270 7   222 48
271 9   222 49
272 7   256 16
273 8   21  13
274 8   137 2
275 8   25  11
276 7   46  6
277 7   554 2
278 6   256 22
279 8   256 23
280 7   20  14
281 9   241 40
282 8   141 2
283 8   285 2
284 7   142 2
285 7   287 2
286 6   22  13
287 6   574 2
288 5   576 2
289 6   17  2
290 6   288 2
291 7   289 2
292 7   146 2
293 8   289 4
294 8   21  14
295 9   287 8
296 8   74  4
297 8   299 2
298 8   254 44
299 7   598 2
300 7   256 44
301 8   299 2
302 7   324 22
303 8   222 81
304 8   19  16
305 9   222 83
306 7   308 2
307 8   308 1
308 6   22  14
309 8   287 22
310 7   222 88
311 8   289 22
312 7   24  13
313 8   324 11
314 8   222 92
315 8   484 169
316 8   79  4
317 9   196 121
318 7   320 2
319 8   320 1
320 6   20  16
321 8   320 1
322 6   324 2
323 7   324 1
324 5   18  2
325 7   324 1
326 6   324 2
327 8   109 3
328 7   324 4
329 9   218 111
330 7   22  15
331 8   220 111
332 8   83  4
333 7   111 3
334 7   167 2
335 8   222 113
336 7   21  16
337 7   674 2
338 6   169 2
339 7   678 2
340 7   338 2
341 8   220 121
342 7   171 2
343 7   222 121
344 7   86  4
345 8   222 123
346 7   324 22
347 9   222 125
348 7   174 2
349 8   350 1
350 6   352 2
351 7   352 1
352 5   22  16
353 7   352 1
354 6   352 2
355 8   352 3
356 7   178 2
357 8   119 3
358 8   352 6
359 7   361 2
360 7   20  18
361 6   19  2
362 8   360 2
363 7   121 3
364 8   26  14
365 8   361 4
366 8   222 144
367 8   256 111
368 7   23  16
369 8   123 3
370 8   368 2
371 8   373 2
372 8   62  6
373 7   484 111
374 7   22  17
375 8   373 2
376 7   378 2
377 8   256 121
378 6   400 22
379 8   378 1
380 7   378 2
381 9   127 3
382 7   384 2
383 8   361 22
384 6   24  16
385 8   384 1
386 7   384 2
387 8   389 2
388 7   194 2
389 7   400 11
390 7   392 2
391 8   222 169
392 6   196 2
393 8   392 1
394 7   392 2
395 8   396 1
396 6   22  18
397 7   398 1
398 5   400 2
399 6   400 1
400 4   20  2
401 6   400 1
402 5   400 2
403 7   400 3
404 6   400 4
405 8   400 5
406 7   400 6
407 9   37  11
408 7   400 8
409 8   398 11
410 8   400 10
411 7   400 11
412 7   206 2
413 8   400 13
414 8   23  18
415 9   399 16
416 7   26  16
417 8   419 2
418 7   22  19
419 7   441 22
420 7   21  20
421 8   399 22
422 6   400 22
423 8   400 23
424 7   400 24
425 8   441 16
426 7   448 22
427 9   425 2
428 7   214 2
429 8   440 11
430 8   428 2
431 8   433 2
432 7   24  18
433 7   444 11
434 7   436 2
435 8   433 2
436 6   218 2
437 7   439 2
438 6   440 2
439 6   441 2
440 5   22  20
441 5   21  2
442 5   444 2
443 6   441 2
444 4   222 2
445 6   444 1
446 5   444 2
447 7   444 3
448 5   224 2
449 7   448 1
450 6   448 2
451 8   440 11
452 6   226 2
453 8   442 11
454 7   452 2
455 7   444 11
456 7   228 2
457 8   441 16
458 7   460 2
459 8   448 11
460 6   462 2
461 7   462 1
462 5   484 22
463 7   441 22
464 6   462 2
465 8   243 222
466 6   444 22
467 8   444 23
468 6   484 16
469 8   468 1
470 7   448 22
471 7   473 2
472 7   484 12
473 6   484 11
474 7   476 2
475 7   473 2
476 6   484 8
477 8   473 4
478 6   480 2
479 7   480 1
480 5   482 2
481 6   482 1
482 4   484 2
483 5   484 1
484 3   22  2
485 5   484 1
486 4   484 2
487 6   484 3
488 5   484 4
489 7   484 5
490 6   484 6
491 8   480 11
492 6   484 8
493 7   482 11
494 7   484 10
495 6   484 11
496 7   484 12
497 7   484 13
498 7   482 16
499 8   483 16
500 6   484 16
501 8   484 17
502 7   480 22
503 8   481 22
504 6   482 22
505 7   483 22
506 5   484 22
507 7   484 23
508 6   254 2
509 8   484 25
510 6   512 2
511 7   512 1
512 5   9   2
513 7   512 1
514 6   512 2
515 8   512 3
516 6   258 2
517 8   484 33
518 7   516 2
519 9   398 121
520 7   26  20
521 8   400 121
522 8   482 40
523 8   512 11
524 7   262 2
525 7   527 2
526 6   528 2
527 6   529 2
528 5   24  22
529 5   23  2
530 6   528 2
531 6   529 2
532 7   266 2
533 7   529 4
534 7   512 22
535 8   529 6
536 8   134 4
537 8   529 8
538 8   516 22
539 8   528 11
540 8   90  6
541 9   528 13
542 9   320 222
543 9   527 16
544 8   34  16
545 8   529 16
546 8   26  21
547 9   483 64
548 7   484 64
549 8   527 22
550 7   25  22
551 7   529 22
552 7   24  23
553 8   529 24
554 6   576 22
555 7   1110    2
556 7   278 2
557 8   555 2
558 8   554 4
559 9   43  13
560 7   576 16
561 8   1122    2
562 8   560 2
563 8   565 2
564 8   484 80
565 7   576 11
566 8   568 2
567 8   565 2
568 7   576 8
569 9   400 169
570 7   572 2
571 8   572 1
572 6   26  22
573 7   574 1
574 5   576 2
575 6   576 1
576 4   24  2
577 6   576 1
578 5   576 2
579 7   576 3
580 6   576 4
581 8   576 5
582 7   576 6
583 9   361 222
584 7   576 8
585 8   574 11
586 8   576 10
587 7   576 11
588 8   42  14
589 8   576 13
590 8   574 16
591 9   480 111
592 7   576 16
593 8   482 111
594 8   27  22
595 7   484 111
596 7   574 22
597 8   484 113
598 6   576 22
599 8   576 23
600 7   576 24
601 9   480 121
602 8   576 26
603 8   482 121
604 8   302 2
605 7   484 121
606 9   101 6
607 8   484 123
608 8   38  16
609 9   484 125
610 9   482 128
611 9   484 127
612 8   306 2
613 9   444 169
614 8   616 2
615 9   123 5
616 7   28  22
617 9   484 133
618 8   574 44
619 9   575 44
620 7   576 44
621 8   623 2
622 7   400 222
623 7   625 2
624 7   26  24
625 6   5   4
626 8   624 2
627 7   625 2
628 8   484 144
629 8   625 4
630 9   30  21
631 9   625 6
632 8   676 44
633 9   211 3
634 9   632 2
635 9   637 2
636 8   318 2
637 8   1274    2
638 8   640 2
639 9   528 111
640 7   32  20
641 9   400 241
642 8   400 242
643 9   400 243
644 7   322 2
645 8   647 2
646 7   648 2
647 7   1294    2
648 6   324 2
649 7   1298    2
650 7   648 2
651 8   649 2
652 7   326 2
653 8   484 169
654 7   676 22
655 9   484 171
656 8   328 2
657 9   219 3
658 8   660 2
659 8   1318    2
660 7   30  22
661 9   439 222
662 8   440 222
663 8   221 3
664 7   666 2
665 8   666 1
666 6   222 3
667 8   666 1
668 7   666 2
669 8   223 3
670 8   448 222
671 9   649 22
672 7   42  16
673 8   674 1
674 6   676 2
675 7   676 1
676 5   26  2
677 7   676 1
678 6   676 2
679 8   676 3
680 7   676 4
681 9   676 5
682 8   31  22
683 9   441 242
684 8   171 4
685 9   444 241
686 8   343 2
687 8   576 111
688 8   43  16
689 9   576 113
690 9   30  23
691 10  448 243
692 8   346 2
693 9   33  21
694 9   672 22
695 9   473 222
696 8   174 4
697 8   576 121
698 7   676 22
699 9   233 3
700 7   350 2
701 9   700 1
702 7   704 2
703 8   704 1
704 6   32  22
705 8   483 222
706 6   484 222
707 8   484 223
708 7   354 2
709 9   484 225
710 8   484 226
711 9   1111    400
712 8   178 4
713 9   729 16
714 8   119 6
715 9   65  11
716 9   358 2
717 9   239 3
718 8   359 2
719 9   720 1
720 7   36  20
721 8   1442    2
722 7   361 2
723 8   241 3
724 8   482 242
725 8   484 241
726 7   33  22
727 7   729 2
728 8   484 244
729 6   6   3
730 8   729 1
731 7   729 2
732 8   244 3
733 8   729 4
734 8   512 222
735 9   245 3
736 7   46  16
737 9   484 253
738 8   123 6
739 9   483 256
740 7   484 256
741 9   484 257
742 8   484 258
743 10  484 259
744 8   746 2
745 9   576 169
746 7   968 222
747 9   746 1
748 7   34  22
749 9   527 222
750 8   528 222
751 8   529 222
752 8   376 2
753 9   529 224
754 8   756 2
755 9   756 1
756 7   378 2
757 9   756 1
758 8   756 2
759 9   33  23
760 8   38  20
761 10  400 361
762 8   254 3
763 10  109 7
764 8   382 2
765 9   255 3
766 8   768 2
767 9   768 1
768 7   32  24
769 9   768 1
770 8   35  22
771 9   257 3
772 8   386 2
773 9   484 289
774 8   258 3
775 10  484 291
776 8   194 4
777 9   111 7
778 7   800 22
779 9   778 1
780 8   390 2
781 9   782 1
782 7   784 2
783 8   784 1
784 6   28  2
785 8   784 1
786 7   784 2
787 9   676 111
788 8   394 2
789 8   800 11
790 7   792 2
791 8   792 1
792 6   36  22
793 8   792 1
794 7   792 2
795 8   796 1
796 6   398 2
797 8   796 1
798 6   800 2
799 7   800 1
800 5   400 2
801 7   800 1
802 6   800 2
803 8   800 3
804 6   402 2
805 8   804 1
806 7   804 2
807 9   796 11
808 7   404 2
809 9   798 11
810 8   808 2
811 8   800 11
812 8   406 2
813 9   800 13
814 8   37  22
815 9   804 11
816 8   34  24
817 9   576 241
818 8   576 242
819 9   576 243
820 8   798 22
821 9   799 22
822 7   800 22
823 9   800 23
824 8   206 4
825 9   1936    1111
826 8   804 22
827 10  484 343
828 8   36  23
829 10  576 253
830 9   574 256
831 10  277 3
832 8   32  26
833 10  119 7
834 8   836 2
835 9   836 1
836 7   38  22
837 9   836 1
838 8   419 2
839 9   840 1
840 7   42  20
841 8   29  2
842 8   840 2
843 9   841 2
844 7   422 2
845 9   169 5
846 8   844 2
847 8   968 121
848 8   424 2
849 9   847 2
850 9   425 2
851 9   972 121
852 8   426 2
853 9   964 111
854 9   852 2
855 9   857 2
856 8   214 4
857 8   968 111
858 8   39  22
859 9   857 2
860 8   43  20
861 9   287 3
862 8   864 2
863 9   864 1
864 7   36  24
865 9   864 1
866 7   888 22
867 9   289 3
868 8   434 2
869 8   1738    2
870 8   872 2
871 8   1742    2
872 7   218 4
873 9   871 2
874 8   437 2
875 9   876 1
876 7   438 2
877 8   888 11
878 7   439 2
879 8   880 1
880 6   40  22
881 7   1762    2
882 6   441 2
883 7   1766    2
884 6   442 2
885 8   883 2
886 6   888 2
887 7   888 1
888 5   222 4
889 7   888 1
890 6   888 2
891 8   81  11
892 6   446 2
893 8   892 1
894 7   892 2
895 8   896 1
896 6   224 4
897 8   896 1
898 7   896 2
899 8   888 11
900 6   30  2
901 8   900 1
902 7   900 2
903 9   43  21
904 7   226 4
905 9   883 22
906 8   884 22
907 9   896 11
908 8   454 2
909 9   887 22
910 7   888 22
911 9   800 111
912 8   38  24
913 8   1826    2
914 8   892 22
915 9   913 2
916 8   458 2
917 10  473 444
918 8   896 22
919 9   920 1
920 7   46  20
921 9   800 121
922 7   924 2
923 8   924 1
924 6   42  22
925 8   484 441
926 7   924 2
927 9   483 444
928 7   464 2
929 9   484 445
930 8   484 446
931 9   932 1
932 7   466 2
933 9   932 1
934 8   932 2
935 9   924 11
936 7   468 2
937 9   936 1
938 8   936 2
939 9   961 22
940 8   470 2
941 9   942 1
942 7   964 22
943 9   942 1
944 7   946 2
945 8   946 1
946 6   968 22
947 8   946 1
948 7   946 2
949 9   946 3
950 7   972 22
951 9   729 222
952 7   476 2
953 8   964 11
954 8   952 2
955 8   957 2
956 7   478 2
957 7   968 11
958 7   960 2
959 8   957 2
960 6   480 2
961 7   31  2
962 6   964 2
963 7   964 1
964 5   482 2
965 7   964 1
966 5   968 2
967 6   968 1
968 4   484 2
969 6   968 1
970 5   968 2
971 7   968 3
972 5   486 2
973 7   972 1
974 6   972 2
975 8   964 11
976 6   488 2
977 8   966 11
978 7   976 2
979 7   968 11
980 7   490 2
981 8   968 13
982 8   960 22
983 8   972 11
984 7   492 2
985 9   963 22
986 7   964 22
987 9   964 23
988 7   966 22
989 8   967 22
990 6   968 22
991 8   968 23
992 7   968 24
993 9   968 25
994 7   972 22
995 9   972 23
996 8   498 2
997 9   999 2
998 8   976 22
999 8   111 9
1000    7   10  3
1001    8   1023    22
1002    7   1024    22
1003    8   1025    22
1004    8   502 2
1005    9   1003    2
1006    8   1008    2
1007    9   1008    1
1008    7   42  24
1009    9   888 121
1010    7   1012    2
1011    8   1012    1
1012    6   46  22
1013    7   2026    2
1014    7   1012    2
1015    8   1013    2
1016    7   254 4
1017    9   113 9
1018    8   1016    2
1019    8   1021    2
1020    7   510 2
1021    7   1023    2
1022    6   1024    2
1023    6   2046    2
1024    5   10  2
1025    6   2050    2
1026    6   1024    2
1027    7   1025    2
1028    7   514 2
1029    8   1025    4
1030    8   1024    6
1031    9   1023    8
1032    7   258 4
1033    8   1035    2
1034    8   47  22
1035    7   2070    2
1036    8   518 2
1037    8   1035    2
1038    9   554 484
1039    9   1023    16
1040    8   40  26
1041    9   1025    16
1042    9   521 2
1043    9   1021    22
1044    8   1022    22
1045    8   1023    22
1046    7   1024    22
1047    8   1025    22
1048    8   262 4
1049    9   968 81
1050    8   525 2
1051    9   1052    1
1052    7   526 2
1053    9   81  13
1054    7   527 2
1055    8   1056    1
1056    6   44  24
1057    7   2114    2
1058    6   529 2
1059    7   2118    2
1060    7   530 2
1061    8   1059    2
1062    7   531 2
1063    9   1059    4
1064    8   266 4
1065    9   1067    2
1066    8   533 2
1067    8   1089    22
1068    8   534 2
1069    8   2138    2
1070    9   535 2
1071    9   119 9
1072    9   134 8
1073    9   1089    16
1074    8   1296    222
1075    9   964 111
1076    9   538 2
1077    9   966 111
1078    8   49  22
1079    8   968 111
1080    8   45  24
1081    9   968 113
1082    9   576 506
1083    9   361 3
1084    9   1062    22
1085    8   1087    2
1086    9   1087    1
1087    7   1089    2
1088    8   1089    1
1089    6   33  2
1090    8   1089    1
1091    7   1089    2
1092    8   42  26
1093    8   1089    4
1094    9   1092    2
1095    8   1111    16
1096    8   548 2
1097    9   1089    8
1098    8   1100    2
1099    8   2198    2
1100    7   50  22
1101    8   2202    2
1102    8   551 2
1103    8   1111    8
1104    7   46  24
1105    8   1107    2
1106    8   1104    2
1107    7   1109    2
1108    7   554 2
1109    6   1111    2
1110    6   2220    2
1111    5   2222    2
1112    6   2224    2
1113    6   1111    2
1114    7   1112    2
1115    7   1111    4
1116    8   1112    4
1117    8   1111    6
1118    9   43  26
1119    8   1111    8
1120    8   224 5
1121    8   2242    2
1122    7   2244    2
1123    8   2246    2
1124    8   1122    2
1125    9   1109    16
1126    8   1148    22
1127    8   1111    16
1128    8   1130    2
1129    9   1107    22
1130    7   1152    22
1131    8   1109    22
1132    8   1110    22
1133    7   1111    22
1134    8   1112    22
1135    8   1111    24
1136    8   568 2
1137    9   968 169
1138    9   1136    2
1139    9   1141    2
1140    8   570 2
1141    8   1152    11
1142    8   1144    2
1143    9   1111    32
1144    7   44  26
1145    9   1024    121
1146    7   1148    2
1147    8   1148    1
1148    6   574 2
1149    8   1148    1
1150    6   1152    2
1151    7   1152    1
1152    5   576 2
1153    7   1152    1
1154    6   1152    2
1155    8   1111    44
1156    6   34  2
1157    8   1156    1
1158    7   1156    2
1159    9   1111    48
1160    7   580 2
1161    9   1150    11
1162    8   1160    2
1163    8   1152    11
1164    8   582 2
1165    9   1152    13
1166    9   53  22
1167    9   1156    11
1168    8   584 2
1169    9   2338    2
1170    8   1148    22
1171    10  1148    23
1172    8   1150    22
1173    9   1151    22
1174    7   1152    22
1175    9   1111    64
1176    8   196 6
1177    9   107 11
1178    8   1156    22
1179    10  957 222
1180    9   590 2
1181    10  1225    44
1182    9   960 222
1183    10  169 7
1184    8   592 2
1185    9   1296    111
1186    8   964 222
1187    10  964 223
1188    8   54  22
1189    9   967 222
1190    7   968 222
1191    9   968 223
1192    8   596 2
1193    10  968 225
1194    8   398 3
1195    9   1196    1
1196    7   598 2
1197    9   399 3
1198    8   1196    2
1199    8   109 11
1200    7   400 3
1201    9   1199    2
1202    8   1200    2
1203    9   401 3
1204    9   86  14
1205    9   241 5
1206    8   402 3
1207    10  964 243
1208    9   302 4
1209    9   968 241
1210    8   55  22
1211    9   968 243
1212    9   202 6
1213    9   729 484
1214    9   607 2
1215    9   243 5
1216    9   38  32
1217    9   1219    2
1218    9   1196    22
1219    8   1221    2
1220    8   2440    2
1221    7   111 11
1222    8   2444    2
1223    8   1221    2
1224    8   968 256
1225    7   35  2
1226    9   968 258
1227    8   1225    2
1228    9   614 2
1229    9   1225    4
1230    9   123 10
1231    9   2462    2
1232    8   44  28
1233    9   2466    2
1234    9   1012    222
1235    10  1013    222
1236    9   206 6
1237    10  1221    16
1238    9   1240    2
1239    9   2478    2
1240    8   62  20
1241    9   1243    2
1242    9   621 2
1243    8   113 11
1244    8   622 2
1245    9   1023    222
1246    8   623 2
1247    9   1025    222
1248    8   48  26
1249    8   2498    2
1250    7   625 2
1251    8   2502    2
1252    8   1250    2
1253    9   1251    2
1254    8   627 2
1255    10  968 287
1256    9   628 2
1257    10  419 3
1258    9   629 2
1259    10  1148    111
1260    9   42  30
1261    9   2522    2
1262    10  631 2
1263    9   1152    111
1264    9   79  16
1265    9   115 11
1266    8   2532    2
1267    9   2534    2
1268    9   784 484
1269    10  1148    121
1270    9   254 5
1271    10  1150    121
1272    8   1274    2
1273    9   1152    121
1274    7   1296    22
1275    9   1274    1
1276    8   58  22
1277    10  1156    121
1278    8   1280    2
1279    9   1280    1
1280    7   64  20
1281    9   1280    1
1282    8   1280    2
1283    9   1285    2
1284    8   800 484
1285    8   1296    11
1286    9   800 486
1287    9   117 11
1288    8   322 4
1289    10  1285    4
1290    8   1292    2
1291    9   1292    1
1292    7   1294    2
1293    8   1294    1
1294    6   1296    2
1295    7   1296    1
1296    5   6   4
1297    7   1296    1
1298    6   1296    2
1299    8   1296    3
1300    7   1296    4
1301    9   1296    5
1302    8   1296    6
1303    10  1292    11
1304    8   326 4
1305    9   1294    11
1306    9   653 2
1307    8   1296    11
1308    8   218 6
1309    8   119 11
1310    8   1332    22
1311    9   1089    222
1312    8   1296    16
1313    10  101 13
1314    9   219 6
1315    9   1331    16
1316    8   1294    22
1317    9   439 3
1318    7   1296    22
1319    9   1296    23
1320    7   220 6
1321    9   1320    1
1322    8   1320    2
1323    8   441 3
1324    9   662 2
1325    9   1323    2
1326    8   221 6
1327    8   1329    2
1328    8   664 2
1329    7   1331    2
1330    7   1332    2
1331    6   11  3
1332    6   222 6
1333    7   1331    2
1334    7   1332    2
1335    8   1331    4
1336    8   668 2
1337    9   1331    6
1338    8   223 6
1339    9   1331    8
1340    8   1296    44
1341    9   1352    11
1342    8   1344    2
1343    9   1332    11
1344    7   224 6
1345    9   1344    1
1346    8   1344    2
1347    9   1331    16
1348    7   674 2
1349    9   1348    1
1350    7   1352    2
1351    8   1352    1
1352    6   676 2
1353    8   123 11
1354    7   1352    2
1355    9   1331    24
1356    7   678 2
1357    9   1356    1
1358    8   1356    2
1359    10  1348    11
1360    8   680 2
1361    10  1350    11
1362    8   1364    2
1363    9   1352    11
1364    7   62  22
1365    9   1364    1
1366    8   1364    2
1367    8   1369    2
1368    8   968 400
1369    7   37  2
1370    9   886 484
1371    8   1369    2
1372    8   888 484
1373    9   1369    4
1374    8   1152    222
1375    9   125 11
1376    8   86  16
1377    10  81  17
1378    8   1600    222
1379    10  1331    48
1380    9   46  30
1381    11  896 485
1382    10  896 486
1383    10  461 3
1384    9   346 4
1385    10  1369    16
1386    8   63  22
1387    10  1386    1
1388    9   1386    2
1389    9   22224   16
1390    9   1412    22
1391    9   1369    22
1392    9   58  24
1393    10  1152    241
1394    9   697 2
1395    10  1152    243
1396    8   698 2
1397    9   127 11
1398    9   233 6
1399    9   2798    2
1400    8   350 4
1401    10  1399    2
1402    9   1400    2
1403    10  1404    1
1404    8   702 2
1405    9   1406    1
1406    7   1408    2
1407    8   1408    1
1408    6   64  22
1409    8   1408    1
1410    7   1408    2
1411    9   1408    3
1412    7   706 2
1413    9   1412    1
1414    8   1412    2
1415    10  1294    121
1416    8   354 4
1417    9   109 13
1418    9   1416    2
1419    9   129 11
1420    9   710 2
1421    10  1408    13
1422    8   1444    22
1423    10  1023    400
1424    9   89  16
1425    10  475 3
1426    9   62  23
1427    10  1449    22
1428    9   42  34
1429    10  1407    22
1430    8   65  22
1431    10  1408    23
1432    9   1408    24
1433    9   1444    11
1434    9   239 6
1435    10  287 5
1436    9   359 4
1437    10  479 3
1438    9   1440    2
1439    10  1440    1
1440    8   40  36
1441    9   1442    1
1442    7   1444    2
1443    8   111 13
1444    6   38  2
1445    8   1444    1
1446    7   482 3
1447    9   1444    3
1448    8   964 484
1449    8   483 3
1450    7   1452    2
1451    8   1452    1
1452    6   484 3
1453    8   1452    1
1454    7   1452    2
1455    8   485 3
1456    8   972 484
1457    9   1455    2
1458    7   486 3
1459    9   1458    1
1460    8   1458    2
1461    9   487 3
1462    8   731 2
1463    9   133 11
1464    8   244 6
1465    10  1024    441
1466    8   1444    22
1467    10  489 3
1468    9   734 2
1469    9   113 13
1470    9   245 6
1471    10  1449    22
1472    8   46  32
1473    10  1352    121
1474    8   1452    22
1475    10  1452    23
1476    9   123 12
1477    10  1455    22
1478    9   1480    2
1479    9   1600    121
1480    8   740 2
1481    10  1479    2
1482    9   1480    2
1483    10  1485    2
1484    9   742 2
1485    9   495 3
1486    9   1488    2
1487    10  1485    2
1488    8   62  24
1489    9   1600    111
1490    9   1488    2
1491    10  497 3
1492    8   746 2
1493    10  964 529
1494    9   1492    2
1495    9   1936    441
1496    8   44  34
1497    9   968 529
1498    9   1496    2
1499    9   1521    22
1500    9   500 3
....    ... ... ...

Based on it, we easily can reconstruct decomposition of each number of the table:
$567 = 565+2 = 576 - 11+2 = 24^2 - 22/2+2 = (22+2)^2-22/2+2$ $\;$: requires $8$ $\;2$s.

Note that "minimal" decompositions of some numbers $n$ require essentially large (in comparison with $n$) parts:
$101 = 2222/22$;
$825 = 1936 - 1111 = (2\times 22)^2 - 2222/2$.


On upper bound.

If for some $n_0$ for all $n \in [n_0, n_0^2]$ works estimation $$ g(n) \le c \log_2 n - 4, \tag{1} $$ then it works for all $n \ge n_0$.

Indeed, for any $n\in [n_0^2, n_0^4]$ we can express $n$ as: $$ n = a^2+b, $$ where
$a = \lfloor \sqrt{n} \rfloor$,
$b = n-a^2 \le 2a\;\;$ (the worst case: when $n=(a+1)^2-1$; then $n-a^2=2a$).

Then in the case of even $b$: $b=2s$: $$ g(b) = g(2s) = 1+g(s) \le 1+g(a); $$ and in the case of odd $b$: $b=2s+1$: $$ g(b)=g(2s+2/2) = 3+g(s) \le 3+g(a); $$ and therefore $$ g(n) = g(a^2+b) \le 1 + g(a) + g(b) \le 1 + g(a) + 3+ g(a) = 4+2g(a), $$ so since $a\in [n_0, n_0^2]$, we rewrite it: $$ g(n) \le 4+2(c \log_2 a - 4) = c \log_2 a^2 - 4 \le c \log_2 n - 4. $$ Based on math.induction, we can expand it for any $n\ge n_0$.

It remains to figure out appropriate value $c$.


Experimentally (see previous answer) for all $n\in [400, 400^2]$ works estimation: $$ g(n) \le 1.5 \log_2 n - 4;\tag{2} $$ therefore for all $n\ge 400$ we can use rough estimation $(2)$.

Check for $n=14885392687$: $g(n) < 46.7$ (not so big improvement ...).


Similarly, the estimation $$ g(n) \le 1.2 \log_2 n - 4;\tag{2'} $$ works for $n\ge 20\;000$.

Check for $n=14885392687$: $g(n) < 36.6$ (slightly better improvement).


I am pretty sure that starting from some $n_0$ we can use value $c=1$, or even less (?)