| Bytes | Lang | Time | Link |
|---|---|---|---|
| 031 | Wolfram Language Mathematica | 190503T043817Z | att |
| 010 | Husk | 201030T155516Z | LegionMa |
| 009 | Gaia | 190502T151201Z | Giuseppe |
| 052 | Wolfram Language Mathematica | 190502T140556Z | ZaMoC |
| 009 | 05AB1E | 190502T135824Z | Emigna |
| 077 | Scala | 190503T092422Z | Peter |
| 008 | Brachylog | 190503T000634Z | Unrelate |
| 034 | Ruby | 190502T221649Z | Value In |
| 054 | C# Visual C# Interactive Compiler | 190502T181908Z | Gymhgy |
| 015 | Clam | 190502T172538Z | Mayube |
| 013 | Japt h | 190502T163905Z | Gymhgy |
| 009 | Jelly | 190502T141348Z | hyper-ne |
| 039 | Javascript ES6 | 190502T145618Z | user8371 |
| 038 | Perl 6 | 190502T143514Z | Jo King |
Wolfram Language (Mathematica), 38 35 31 bytes
If[i∣n,n/=i;1,0]~Sum~{i,n=#}&
Greedy algorithm. Times out on TIO on larger inputs such as 1099511627776.
Gaia, 10 9 bytes
Π=
dz↑⁇(l
Follows the same "algorithm" as seen elsewhere -- filter the divisor powerset for the longest with product equal to the number and return its length.
| helper function
Π= | is prod(list)==n (implicit)?
|
| main function; implicitly takes n
dz | divisor powerset (in decreasing order of size)
↑⁇ | filter by helper function
(l | take the first element and take the length (implicitly output)
Wolfram Language (Mathematica), 52 bytes
Max[Length/@Cases[Subsets@Divisors@#,{a__}/;1a==#]]&
4-bytes saved thanks to @attinat
Here is also a 153 bytes version that calculates 1099511627776 and 10^15
Max[Length/@Table[s=RandomSample@Flatten[Table@@@FactorInteger[#]];Last@Select[Times@@@TakeList[s,#]&/@IntegerPartitions@Length@s,DuplicateFreeQ],5!]]+1&
The result for 10^15 is 12
{1, 2, 4, 5, 10, 16, 25, 40, 50, 100, 125, 250}
05AB1E, 9 bytes
Very inefficient. Will time out on TIO for numbers with a large amount of divisors.
ÑæʒPQ}€gZ
Explanation
Ñ # push a list of divisors of the input
æ # push the powerset of that list
ʒPQ} # filter, keep only the lists whose product is the input
€g # get the length of each
Z # take the maximum
Scala, 77 bytes
def f(n:Long)={var(m,c,i)=(n,1,2L);while(i<=m){if(m%i==0){m/=i;c+=1};i+=1};c}
Brachylog, 8 bytes
f;?⟨⊇×⟩l
(The naive approach, {~×≠l}ᶠ⌉, generates an infinite number of solutions with extra 1s before eliminating them with ≠, and thus fails to actually terminate. It's not a problem, though, since it's for the same byte count!)
Takes input through the input variable and output through the output variable. The header on TIO contains a copy of most of the code for the sake of showing you what the factor list is, but this works perfectly fine without it. Since ⊇ gives larger sublists first, this predicate essentially does the same thing as most other answers, but without explicitly generating and filtering the complete powerset of the factors, thanks to backtracking.
The output
l is the length of
⊇ a sublist (the largest satisfying these constraints)
f of the factors of
the input
; ⟨ ⟩ which
× with its elements multiplied together
? is the input.
Ruby, 34 bytes
Obviously times out on that massive number, but will eventually time out if given enough time on another machine.
->n{(1..n).count{|e|n%e<1?n/=e:p}}
C# (Visual C# Interactive Compiler), 54 bytes
int f(int n,int i=0)=>n%++i<1?1+f(n/i,i):n>i?f(n,i):0;
Uses the same approach as @vrugtehagel's and @JoKing's answers.
Clam, 15 bytes
p}_`nq#:;qQ@s~Q
TIO link coming soon (when dennis pulls)
Basically a port of @Emigna's 05AB1E solution.
Explanation
- Implicit Q = first input
p - Print...
} - The last element of...
_ - Sorted...
`nq - Lengths of... (map q => q.len)
@s - Items in powerset of
~Q - Proper divisors of Q
# - Where... (filter)
;q - Product of subset
: - Equals...
Q - Q
Javascript (ES6), 39 bytes
f=(n,i=0)=>n%++i?n>i&&f(n,i):1+f(n/i,i)
There's probably a few bytes that can be saved here and there. Just uses the greedy algorithm for the factors.
Perl 6, 38 bytes
{$!=$_;+grep {$!%%$_&&($!/=$_)},1..$_}
Takes the greedy approach to selecting divisors.