5

As a simple 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?

codebpr
  • 2,233
  • 1
  • 7
  • 26
Klaas
  • 55
  • 3

6 Answers6

11
Times @@ Power @@@ {{2, 1}, {3, 2}, {43, 5}, {26684839, 1}}
Julian
  • 492
  • 4
  • 9
4
Times @@ (#[[1]]^#[[2]] & /@ {{2, 1}, {3, 2}, {43, 5}, {26684839, 1}})
David G. Stork
  • 41,180
  • 3
  • 34
  • 96
4

Also

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

Inner[Power, ## & @@ (pf\[Transpose]), Times]
(* 70612139395722186 *)
kglr
  • 394,356
  • 18
  • 477
  • 896
4

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]
lalmei
  • 3,332
  • 18
  • 26
3
Table[#1, #2] & @@@ lis // Map[Apply[Sequence]] // Apply[Times]

or

Times @@ (Sequence @@ Table[#1, #2] & @@@ lis)

or

Times @@ (Times @@ Table[#1, #2] & @@@ lis)

or

lis /. {a_, b_} :> a^b // Times @@ # &

Result:

70612139395722186

Syed
  • 52,495
  • 4
  • 30
  • 85
1
list = {{2, 1}, {3, 2}, {43, 5}, {26684839, 1}};

Two slot-free variants of Syed's solution:

Using Splice (new in 12.1)

Times @@ Splice @* Table @@@ list

70612139395722186

Using MapApply (new in 13.1)

Times @@ Flatten @ MapApply[Table] @ list

70612139395722186

eldo
  • 67,911
  • 5
  • 60
  • 168