I would like to format the output. For example, the following code gives
For[n=2,n<=10,n++,
factorization =FactorInteger[n];
length=Length[factorization];
If[length==1,
factorization =(Superscript@@@FactorInteger[n])[[1]],
factorization =CenterDot@@(Superscript@@@FactorInteger[n])
];
Print["n = ", n, " = ", factorization, ", number of prime factors = ", length];
]
But what I want is something similar to the following (but better alignment)
I know there is Grid, but I don't know how to use them in this current case. Also, I prefer a simpler solution (if there is), such as one can specify a "field width" like in the C language.
Grid
? Layout-wise, this will be much more comfortable and powerful. $\endgroup$Reap[For[n = 2, n <= 10, n++, factorization = FactorInteger[n]; length = Length[factorization]; If[length == 1, factorization = (Superscript @@@ FactorInteger[n])[[1]], factorization = CenterDot @@ (Superscript @@@ FactorInteger[n])]; Sow[{"n = ", n, " = ", factorization, "; number of prime factors = ", length}];]][[2, 1]] // Grid
$\endgroup$Reap/Sow
:P $\endgroup$