Skip to main content
added 9 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

#MATL, 12 bytes

|1>?GtYf/s}0

Try it online!

###Explanation

Consider an integer a with |a|>1, and let itsthe (possibly repeated) prime factors of |a| be f1, ..., fn. Then the desired result is a·(1/f1 + ... + 1/fn).

|1>     % take input's absolute value. Is it greater than 1?
?       % if so:
  Gt    %   push input twice
  Yf    %   prime factors. For negative input uses its absolute value
  /     %   divide element-wise
  s     %   sum of the array
}       % else:
  0     %   push 0

#MATL, 12 bytes

|1>?GtYf/s}0

Try it online!

###Explanation

Consider an integer a with |a|>1, and let its (possibly repeated) prime factors be f1, ..., fn. Then the desired result is a·(1/f1 + ... + 1/fn).

|1>     % take input's absolute value. Is it greater than 1?
?       % if so:
  Gt    %   push input twice
  Yf    %   prime factors. For negative input uses its absolute value
  /     %   divide element-wise
  s     %   sum of the array
}       % else:
  0     %   push 0

#MATL, 12 bytes

|1>?GtYf/s}0

Try it online!

###Explanation

Consider an integer a with |a|>1, and let the (possibly repeated) prime factors of |a| be f1, ..., fn. Then the desired result is a·(1/f1 + ... + 1/fn).

|1>     % take input's absolute value. Is it greater than 1?
?       % if so:
  Gt    %   push input twice
  Yf    %   prime factors. For negative input uses its absolute value
  /     %   divide element-wise
  s     %   sum of the array
}       % else:
  0     %   push 0
added 505 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

MATL, 12 bytes

#MATL, 12 bytes

TFm|1>?0}GtYf/s}0

Try it online!Try it online!

###Explanation

Consider an integer a with |a|>1, and let its (possibly repeated) prime factors be f1, ..., fn. Then the desired result is a·(1/f1 + ... + 1/fn).

|1>     % take input's absolute value. Is it greater than 1?
?       % if so:
  Gt    %   push input twice
  Yf    %   prime factors. For negative input uses its absolute value
  /     %   divide element-wise
  s     %   sum of the array
}       % else:
  0     %   push 0

MATL, 12 bytes

TFm?0}GtYf/s

Try it online!

#MATL, 12 bytes

|1>?GtYf/s}0

Try it online!

###Explanation

Consider an integer a with |a|>1, and let its (possibly repeated) prime factors be f1, ..., fn. Then the desired result is a·(1/f1 + ... + 1/fn).

|1>     % take input's absolute value. Is it greater than 1?
?       % if so:
  Gt    %   push input twice
  Yf    %   prime factors. For negative input uses its absolute value
  /     %   divide element-wise
  s     %   sum of the array
}       % else:
  0     %   push 0
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

MATL, 12 bytes

TFm?0}GtYf/s

Try it online!