I would like to draw trees like this:
In the first branch a child is calculated by Euclidean Division with the divisor 2 from its parent. In the second branch a child is calculated by Euclidean Division with divisor 3 from its parent. And so on up to the divisor floor(root/2)
This code is able to draw the first branch for arbitrary roots.
\documentclass[border=10pt]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
div2/.style={
append/.process={ Ow+PS _>? l_w2 {content}{int(floor(##1/2))}{1}{div2}{}{[##1,##2]}},
},
[10, div2]
\end{forest}
\end{document}
To automatically draw the other branches I tried this:
\documentclass[border=10pt]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
divn/.style args={1} ={
append/.process={ Ow+PS _>? l_w2 {content}
{int(floor(##1/#1))}{1}{divn}{}{[##1,##2]}},
},
%
tempcounta = {1},
branches/.style={
until{2*tempcounta > content}{
divn={content},
tempcounta/.pgfmath={tempcounta+1},
},
},
%
%
[3, branches]
\end{forest}
\end{document}
EDIT: Based on the comments of cfr, I now have this:
\documentclass[border=10pt]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
divn/.style args={1} ={
append/.process={ Ow+PS _>? l_w2 {content}{int(floor(##1/#1))}{1}{divn={tempcounta}}{}{[##1,##2]}},
},
%
tempcounta = 1,
branches/.style={
until={<Rw+P O+P> {tempcounta}{##1*2}{content}}{
branches/.append style={divn={tempcounta}},
tempcounta'+=1,
},
},
%
%
[5, branches]
\end{forest}
\end{document}


append/.process={ O+nw+P Sn=?_ lw2 {content}{int(floor(##1/2))}{1}{}{div2}{[##2, ##1]} }, though I'm not sure about this. – cfr Jul 23 '17 at 10:20untilneeds an=.divn={content}passes the textcontentto the styledivnwhich does nothing at all with whatever argument is passed to it. The incremented counttempcountawill not be an integer since.pgfmathwill not yield an integer.tempcounta'+=1would be better here. – cfr Jul 23 '17 at 10:252*tempcounta > content: neithertempcountanorcontentis a number. These are just text strings. So>makes no sense and nor does2*.2*tempcountais like2*abcdefgi.e. undefined. – cfr Jul 23 '17 at 10:26