3
$\begingroup$

For example, there is a list of prime factors.

{{2, 1}, {3, 2}, {43, 5}, {26684839, 1}}

How to combine them to the number 70612139395722186 using Mathematica?

$\endgroup$
8
$\begingroup$
Times @@ Power @@@ {{2, 1}, {3, 2}, {43, 5}, {26684839, 1}}
$\endgroup$
3
$\begingroup$
Times @@ (#[[1]]^#[[2]] & /@ {{2, 1}, {3, 2}, {43, 5}, {26684839, 1}})
$\endgroup$
3
$\begingroup$

Here is another one

primefactors = {{2, 1}, {3, 2}, {43, 5}, {26684839, 1}};

Fold[Times[#1, Power @@ #2] &, 1, primefactors]

70612139395722186

If the list gets larger enough, you can use ParallelCombine to MapReduce it,

ParallelCombine[Fold[Times[#1, Power @@ #2] &, 1, #]&, primefactors, Times]

For the list of current size, this actually only slows it down. And it can be used with any of the methods show here so far. If the method does it with as a function, f[#]& then:

 ParallelCombine[f[#]&, primefactors, Times]
$\endgroup$
2
$\begingroup$

Also

pf = {{2, 1}, {3, 2}, {43, 5}, {26684839, 1}};

Inner[Power, ## & @@ (pf\[Transpose]), Times]
(* 70612139395722186 *)
$\endgroup$
  • $\begingroup$ Equivalently, Inner[Power, pf[[All, 1]], pf[[All, 2]], Times]. $\endgroup$ – J. M. will be back soon May 4 '15 at 4:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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