Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Harmonic divisor numbers

Consider the \4ドル\$ divisors of \6ドル\$: \1,ドル 2, 3, 6\$. We can calculate the harmonic mean of these numbers as

$$\frac 4 {\frac 1 1 + \frac 1 2 + \frac 1 3 + \frac 1 6} = \frac 4 {\frac {12} 6} = \frac 4 2 = 2$$

However, if we take the \6ドル\$ divisors of \12ドル\$ (\1,ドル 2, 3, 4, 6, 12\$) and calculate their harmonic mean, we get

$$\frac 6 {\frac 1 1 + \frac 1 2 + \frac 1 3 + \frac 1 4 + \frac 1 6 + \frac 1 {12}} = \frac 6 {\frac {28} {12}} = \frac {18} {7}$$

Ore numbers or harmonic divisor numbers are positive integers \$n\$ where the harmonic mean of \$n\$'s divisors is an integer, for example \6ドル\$. They are A001599 in the OEIS.

The first few Ore numbers are

1, 6, 28, 140, 270, 496, 672, 1638, 2970, 6200, 8128, 8190, ...

Point of interest: this sequence contains all the perfect numbers (see Wikipedia for a proof).


This is a standard challenge. You may choose which of the following three options to do:

  • Take a positive integer \$n\$ and output the first \$n\$ Ore numbers.
  • Take a positive integer \$n\$ and output the \$n\$th Ore number.
    • You may use 0-indexing (so non-negative input) or 1-indexing, your choice
  • Take no input, and output the never ending list of Ore numbers.

Note that your answer cannot fail due to floating point errors.

This is , so the shortest code in bytes wins.

Answer*

Draft saved
Draft discarded
Cancel
15
  • 2
    \$\begingroup\$ 40 bytes \$\endgroup\$ Commented Nov 24, 2021 at 22:49
  • \$\begingroup\$ How do you measure the bytes in Mathematica? \$\endgroup\$ Commented Nov 25, 2021 at 16:04
  • \$\begingroup\$ @EGME Mathematica doesn't have any special encoding, so we just use UTF-8, where both and are encoded in 3 bytes. \$\endgroup\$ Commented Nov 25, 2021 at 16:07
  • \$\begingroup\$ So how are you measuring the bytes then, for the whole thing? Do you just take the character string and see how much space it needs? \$\endgroup\$ Commented Nov 25, 2021 at 16:08
  • 1
    \$\begingroup\$ Thanks, I think I got it ... let’s see if I can better this :) \$\endgroup\$ Commented Nov 25, 2021 at 16:20

AltStyle によって変換されたページ (->オリジナル) /