Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to write a Mathematica code to decompose an integer into two or more parts with primes in special intervals.

For instance, I want to decompose $m=\binom{n}{k}$ into two parts U and V such that $\binom{n}{k}=UV$ and $$ U=\prod_{\substack{p\le k\\p^\alpha||m}} p^{\alpha} $$ and $$ V=\prod_{\substack{k<p\le n\\p^\alpha||m}} p^{\alpha} $$ where $p^\alpha||m$ mean $p^\alpha$ is the maximum prime power dividing m.

I tried

Product[If[Element[p,Primes]&&Mod[Binomial[n, k], p] == 0, p, 1], {p,2,k-1}]

Product[If[Element[p,Primes]&&Mod[Binomial[n, k], p] == 0, p, 1], {p,k,n}]

, but it was not true

share|improve this question
@ Öskå, I want the Mathematica code to do this –  asad Aug 6 at 11:15
Have you tried anything? Or do you expect an answer without producing any relevant effort? –  Öskå Aug 6 at 11:25
What have you tried in Mathematica? –  blochwave Aug 6 at 11:25
I tried >>Product[If[Mod[Binomial[n, k], p] == 0, p, 1], {p,k,n}], but it was not true –  asad Aug 6 at 17:10

2 Answers 2

up vote 3 down vote accepted

@asad the comments are all appropriate and (if I understand your aim), I present a way to implement to perhaps kickstart your own approach. However, I suggest in future you post an attempt, however imperfect. Further, it is helpful to post a small example so people can be clear about what you mean. Finally, if I misunderstand your aim then comment, otherwise I hope this motivates you try your own code, improve, modify etc. Otherwise, your future questions will probably fall on deaf ears...but more importantly you will not develop your own experience.


dec[n_, k_] := Module[
  {num, u},
  num = Binomial[n, k];
  u = Times @@ (#1^#2 & @@@ 
      Cases[FactorInteger[num], {_?(# < k &), _}]); # -> 
     Times @@ (HoldForm[#1^#2] & @@@ (FactorInteger@#)) & /@ {u, 


grd = Grid[
  Table[{StyleBox[RowBox[{"(", GridBox[{{17}, {j}}], ")"}], 
      SpanMaxSize -> Infinity] // DisplayForm, Binomial[17, j], 
    dec[17, j]}, {j, 1, 17}], Frame -> All]

enter image description here

share|improve this answer

The following function splits m=Binomial[n,k] into one or two parts whose product is m. The parts satisfy the conditions you specified, to the best of my understanding.

UVfactors[n_, k_] :=
   With[{f = FactorInteger[Binomial[n, k]]},
      Print[Binomial[n, k]];
         Map[#[[All,1]]^#[[All,2]]&, SplitBy[f, UnitStep[k - #[[1]]]&]],
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.