[Question]
  [
[Euler's numerus idoneus](https://en.wikipedia.org/wiki/Idoneal_number), or idoneal numbers, are a finite set of numbers whose exact number is unknown, as it depends on whether or not the [Generalized Riemann hypothesis](https://en.wikipedia.org/wiki/Generalized_Riemann_hypothesis) holds or not. If it does, there are exactly 65 idoneal numbers. If not, there are either 66 or 67. For the purposes of this challenge, we'll revolutionise mathematics and say that the Generalised Riemann hypothesis is true (I'd prove it, but I'm trying to golf the challenge body).
Under this assumption, the idoneal numbers are
```
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 15, 16, 18, 21, 22, 24, 25, 28, 30, 33, 37, 40, 42, 45, 48, 57, 58, 60, 70, 72, 78, 85, 88, 93, 102, 105, 112, 120, 130, 133, 165, 168, 177, 190, 210, 232, 240, 253, 273, 280, 312, 330, 345, 357, 385, 408, 462, 520, 760, 840, 1320, 1365, 1848
```
This is [A000926](https://oeis.org/A000926), and many different ways to describe this sequence can be found there. However, we'll include two of the most standard ones here:
* A positive integer \$D\$ is idoneal if, for any integer expressible in the form \$x^2 \pm Dy^2\$ in exactly one way (where \$x^2\$ and \$Dy^2\$ are co-prime), that integer is either a prime power, or twice a prime power.
For example, let \$D = 3\$. \$3\$ is idoneal, meaning that all integers that can be expressed as \$x^2 \pm 3y^2\$ for exactly one co-prime pair \$(x, y)\$ are either primes \$p\$, powers of primes \$p^n\$ or twice a prime power \$2p^n\$. As an example, \$(x, y) = (2, 3)\$ yields \$29\$ as \$x^2 + 3y^2\$. \$29\$ is a prime, and cannot be expressed in the form \$x^2 \pm 3y^2\$ for any other co-prime pair \$(x, y)\$.
* Alternatively (and rather more simply), a positive integer \$n\$ is idoneal iff it cannot be written in the form \$ab + ac + bc\$ for distinct positive integers \$a, b, c\$
For example, \$11 = 1\times2 + 1\times3 + 2\times3\$, therefore, \$11\$ is not idoneal.
This is a standard [sequence](/questions/tagged/sequence "show questions tagged 'sequence'") challenge, you may choose one of the following three options:
* Take an integer \$n\$ (either \$0 \le n < 65\$ or \$0 < n \le 65\$, your choice) as input, and output the \$n\$th (either 0 or 1 indexed, also your choice) idoneal number. **You may choose how to order the idoneal numbers**, so long as its consistent.
* Take a positive integer \$1 \le n \le 65\$ and output the first \$n\$ idoneal numbers. Again, you may choose how to order the idoneal numbers.
* Output all 65 idoneal numbers, in any order, with no duplicates.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins
  
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 53 bytes
```
Range[7!]/.<|Array[+##(3#+#2)-#3#->Set@$&,49+0{,,}]|>
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7PygxLz012lwxVl/PpsaxqCixMlpbWVnDWFlb2UhTV9lYWdcuOLXEQUVNx8RS26BaR6c2tsbuf0BRZl6JQxoXhPZJzUsvyXBI@w8A "Wolfram Language (Mathematica) – Try It Online")
Outputs all(?) 65 idoneal numbers. Filters out numbers of the form \$a(a+b)+(a+b)(a+b+c)+(a+b+c)a\$ with \$a,b,c\$ positive integers.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 13 bytes
```
2ȷœc3ṙ€1ḋƊḟ@R
```
[Try it online!](https://tio.run/##ASEA3v9qZWxsef//Msi3xZNjM@G5meKCrDHhuIvGiuG4n0BS//8 "Jelly – Try It Online")
First Jelly answer! Prints all ideonal numbers.
Gosh this was painful. This *should* work given several terabytes of RAM and a couple of hours. To see, replace `2ȷ`(2000) with 20 or something.
-10 thanks to Dude coinheringaahing.
```
2ȷœc3          # Combinations of 1..2000 of length 3 
     ṙ€1ḋ      # Calculate ab+ac+bc for each
         Ɗḟ@   # Remove these from 
2ȷ          R  # 1...2000
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 30 bytes
```
Ｆ⁹⁹ＦιＦκ⊞υ⁺×⊕ι⁺⊕κ⊕λ×⊕κ⊕λＩ⁻…¹⊗φυ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z8tv0hBw9JSUwHMyITS2ZoKAaXFGRqlOgoBOaXFGiGZuanFGp55yUWpual5JakpQJVQKWTBbKAgMj9HUxMogqkZmzpNa66Aosy8Eg3nxOISDd/MPKDZQYl56akahjoKLvmlSTlAhYYGBgYgI0tB6v///69blgMA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
Ｆ⁹⁹ＦιＦκ
```
Loop over distinct `100 > a > b > c > 0`. (Replacing `⁹⁹` with `φ` would save a byte but make the code too slow for TIO.)
```
⊞υ⁺×⊕ι⁺⊕κ⊕λ×⊕κ⊕λ
```
Calculate `ab + ac + bc`.
```
Ｉ⁻…¹⊗φυ
```
Take the range from `1` to `1999` and remove all values that resulted from the above calculation.
[Answer]
# [R](https://www.r-project.org/), ~~72~~ ~~65~~ 62 bytes
```
r=i=1:2e3
for(a in r)for(b in a+r)i[(b+r)*(a+b)+a*b]=F;r[i[r]]
```
[Try it online!](https://tio.run/##K/r/v8g209bQyijVmCstv0gjUSEzT6FIE8RMAjETtYs0M6M1koCUlkaidpKmdqJWUqytm3VRdGZ0UWzs//8A "R – Try It Online")
Outputs all idoneal numbers in ascending order.
The TIO link will time-out, since `r` is needlessly set to `1...2000` to save bytes; [here](https://tio.run/##K/r/v8jW0MrS0rqoyDYTyDJKNeZKyy/SSFTIzFMo0gQxk0DMRO0izcxojSQgpaWRqJ2kqZ2olRRr6wbUF50ZXVQUG/v/PwA) is a link to a version with `r` initialized to `1...99` instead, which doesn't time-out (and still gives the right output).
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 17 bytes
```
∞'£ɾ3ḋ'Ǔ*∑¥=;ḃ;?i
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=&code=%E2%88%9E%27%C2%A3%C9%BE3%E1%B8%8B%27%C7%93*%E2%88%91%C2%A5%3D%3B%E1%B8%83%3B%3Fi&inputs=5&header=&footer=)
Warning: This will *not work* for n ≥ 7. It's just too slow.
```
∞'            ;?i # Get the nth number where...
             ḃ    # None of
   ɾ3ḋ'     ;     # The ways you can choose 3 numbers less than n
       Ǔ*∑        # Have ab+ac+bc...
  £       ¥=      # Equal n
```
[Answer]
# [JavaScript (V8)](https://v8.dev/), ~~87~~ 85 bytes
*Saved 2 bytes thanks to @tsh*
A full program printing the sequence in reverse order.
```
for(i=2e3;--i;)for(a=99;--a?b=~a&&a:print(i);)while(c=--b)while(--c)a*=a*b+a*c+b*c!=i
```
[Try it online!](https://tio.run/##LcdBDkAwEAXQs9hIW5kNGzQTZ/mdECOClLBz9SKxe2/CiV2ibgeddUrDGo1y2VeeSL39Cm6ad@gC38hztFvU5TBqvb1GnXsjTBR@E4mFY7hQwEkRnGSsKT0 "JavaScript (V8) – Try It Online")
### Commented
```
for(                 // 1st loop
  i = 2e3;           // going from i = 1999 to i = 1
  --i;               //
)                    //
  for(               //   2nd loop
    a = 99;          //   starting with a = 99
    --a ?            //   decrement a; if it's not zero:
      b = ~a && a    //     stop if a = -1, otherwise set b to a
    :                //   else:
      print(i);      //     we've reached a = 0: print i
  )                  //
    while(c = --b)   //     3rd loop going from b = a - 1 to b = 1
      while(--c)     //       4th loop going from c = b - 1 to c = 1
        a *=         //         clear a if ab + ac + bc is equal to i,
          a * b +    //         which will turn it into -1 on the next
          a * c +    //         iteration of the 2nd loop
          b * c != i //         (otherwise, leave it unchanged)
```
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), 23 bytes [SBCS](https://github.com/abrudz/SBCS)
```
(⍳!7)~(1⊥2×/4⍴+\)¨⍳3⍴50
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=03jUu1nRXLNOw/BR11Kjw9P1TR71btGO0Ty0AihhDGSbGgAA&f=JY4xjgIxDEX7OYXpQGuJOHYmmbtwkKGhRAIJabutFwmJfvcE7E1ykv0/FPF4/L79/9rPn9t@@9nU3Wlr/frIf1/76Lffj8Pu9QRw9CVN/Xo/QmoqWcVVQqWozCpVpaksKpbwAA3UwAzQgDJ3MM9YyZhnzBxah86xHegDPMACrGBW8J0xr3xgFf8NvNGK9xONEl2GZaa3j0I6D3toreKYLYkpWHzkYFegy5WlMQuv@EjFGM4MTsNIuBIzaKFHZagWw@jtOaxatGntl@/j1C/39R8&i=AwA&r=tryapl&l=apl-dyalog&m=tradfn&n=f)
A full program that prints all 65 terms. Essentially the same strategy as [att's Mathematica answer](https://codegolf.stackexchange.com/a/233947/78410). All attempts to factor out `⍳!7` failed, so here goes an efficient solution.
### How it works
```
(⍳!7)~(1⊥2×/4⍴+\)¨⍳3⍴50    Full program; no input
                  ⍳3⍴50    50x50x50 cube containing coordinates of each cell
      (         )¨         For each item...
              +\             Cumulative sum
       1⊥2×/4⍴               From a, b, c compute ab+bc+ca
(⍳!7)~                     Remove all numbers appearing in ^ from 1..5040
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 75 bytes
```
p [*1..2e3]-(r=*1..56).product(r,r).map{|i|a,b,c=i;a<b&&b<c ?a*b+b*c+c*a:0}
```
[Try it online!](https://tio.run/##KypNqvz/v0AhWstQT88o1ThWV6PIFsQ2NdPUKyjKTylNLtEo0inS1MtNLKiuyaxJ1EnSSbbNtE60SVJTS7JJVrBP1ErSTtJK1k7WSrQyqP3/HwA "Ruby – Try It Online")
A full program printing an array.
An array of the numbers `1..2000` is created and all non-ideonal numbers deleted from it. The smallest value of range `r` that works is `1..56`. Reducing the number below 56 fails to delete `1012` corresponding to `a,b,c = 5,12,56`.
[Answer]
# [Python 3](https://docs.python.org/3/), ~~93~~ 82 bytes
```
R=range(1,2000)
print({*R}-{a*b+c*(a+b)for a in R for b in R for c in R if a<b<c})
```
[Try it online!](https://tio.run/##pZFNboMwEIX3nGJ2/MSV/Ad2pHAJtm0X4JIGVSKIUKkV4uz0jdMqB@jCw3i@mXlPZvpeLtfR7HtTz@343mdKaCllnkzzMC7ZWjTb09oW3SEUWXvo8vN1ppaGkRritHuk4Z4OZ2pP3Sls@X6r/zGe9F9TH5b@jWpalSAtyAiygkpBlSAnyAs6ClISB1CBKjAFqIA0z6CuMaJR16gZ9Br0GUxb5BbcglmwErUS3wp1xwfM4e7BPUvxfslCklWipGZtEwPTKsqjVzksU0fJLjiY6IOzEn3acfDshbeY6IptGPZgWNBKbLEVaMkajk15G4XumlHKW78l4dKHj37GK2Xpy6d2NqSCYqZM@vcbf5ueH29a0@01338A "Python 3 – Try It Online")
Outputs all the idoneal numbers (works but times out on TIO).
This version works on TIO:
# [Python 3](https://docs.python.org/3/), ~~103~~ 92 bytes
```
R=range(1,99)
print({*range(1,2000)}-{a*b+c*(a+b)for a in R for b in R for c in R if a<b<c})
```
[Try it online!](https://tio.run/##rVHLboMwELznK/bGI67kF9hI4SdybXsAlySoEkGESq0Q305nnUb5gR68jGd2d0Zm/Jkv18Fs27GemuHcpUpUVbYbp36Y0yV/cFpKma0vS5O3@5Cnzb7NTteJGuoHOhLD9gnDHfYnag7tIazZdqv/adWu@x67MHcfVNOiBGlBRpAVVAgqBTlBXlAlSEkciAqqgqYgKkiaZ8BrjGjwGpxBr0GfwbQFttAtNAutAFfgW4J3fKA53D10z1a8X7KRZJdoqdnbxMJqGe3RqxyWqUpyCi4m5mBUoE87Lp6z8BYTU3EMwxkMG1qJLbaEWrCH41DeRqO7Z7Ty1q@7cOnCZzfhldLk7Us7GxJBESmTPH7vX9Pr801rur1n2y8 "Python 3 – Try It Online")
*Saved 11 bytes thanks to [FryAmTheEggman](https://codegolf.stackexchange.com/users/31625/fryamtheeggman)!!!*
[Answer]
# [jq](https://stedolan.github.io/jq/), 76 bytes
```
[range(2e3)+1]-[[range(56)+1]|.[]as$a|[.[]+$a][]as$b|$a*$b+($a+$b)*(.[]+$b)]
```
[Try it online!](https://tio.run/##yyr8/z@6KDEvPVXDKNVYU9swVjcayjc1A3Fr9KJjE4tVEmuigQxtlcRYMDepRiVRSyVJW0MlUVslSVNLAyyZpBn7/7@SEgA "jq – Try It Online")
I don't really know why `[.[]+$a][]` and `.[]+$a` have different behavior.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 58 bytes
```
Select[Range[7!],!Reduce[a(b+c)+b*c-#==0<a<b<c,Integers]&]
```
[Try it online!](https://tio.run/##BcG9CoAgEADgVymC6MfAdgXXtqgxGs7rMCEd7Hr@6/sS8E0JOCJIsLLTQ8jHBjmQm7VW9UbXh3RA50fsRz/g1FirDRhvUC2ZKVB5z/aUtcTMlQsiPw "Wolfram Language (Mathematica) – Try It Online") (here are values <100 because TIO times out)
-1 byte from Dude coinheringaahing  
-8 bytes from @att
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 13 bytes
```
⁹œc3P-Ƥ€§ṬCTḣ
```
[Try it online!](https://tio.run/##y0rNyan8/9/I4OjkZOMA3WNLHjWtObT84c41ziEPdyz@b2xwuB0o4v4fAA "Jelly – Try It Online")
Monadic link that returns the first n terms. The leading `⁹` (constant 256) is necessary to get the correct output for n = 1 and 2 (otherwise the output is empty for those two inputs). The linked code has `⁹` replaced by `20` for demonstration purposes.
### How it works
```
⁹œc3P-Ƥ€§ṬCTḣ    Monadic link. Left arg = n, the number of terms
⁹œc3             3-combinations of 1..256
    P-Ƥ€§        ab+bc+ca for each row
         ṬCT     List of numbers in 1..max(above) that do not appear
                 in the above list
            ḣ    Take first n
```
In order to filter out all `ab+bc+ca` numbers before 1848, the input numbers should be at least:
* 56 if you use "3-combinations of 1..(some fixed number)"
* 44 if you use "cumulative sums of 3rd cartesian power of 1..(some fixed number)"
In both cases, the hardest one to filter out is `(5, 12, 56) → 1012`. The next hardest is `(8, 17, 51) → 1411`.
---
# [Jelly](https://github.com/DennisMitchell/jelly), 14 bytes
```
³œc3P-Ƥ€§2ȷR¤ḟ
```
[Try it online!](https://tio.run/##ASEA3v9qZWxsef//wrPFk2MzUC3GpOKCrMKnMsi3UsKk4bif//8 "Jelly – Try It Online")
Full program that prints all 65 terms. This one finishes within a few seconds without modification.
### How it works
```
³œc3P-Ƥ€§2ȷR¤ḟ    Niladic chain.
³œc3              3-combinations of 1..100
    P-Ƥ€§         Compute ab+bc+ca for each row
         2ȷR¤ḟ    Filter out the above from 1..2000
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 14 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
₄·LD3.ÆεĆü*O}K
```
Outputs all 65 values.
[Try it online (with `≤2000` replaced with `≤50`).](https://tio.run/##yy9OTMpM/f/f1MDHxVjvcNu5rUfaDu/R8q/1/v8fAA)
**Explanation:**
```
₄            # Push 1000
 ·           # Double it to 2000
  L          # Pop and push a list in the range [1,2000]
   D         # Duplicate this list
    3.Æ      # Get all triplets with unique integers
       ε     # Map each triplet to:
        Ć    #  Enclose; append its own head: [a,b,c] to [a,b,c,a]
         ü   #  For each overlapping pair:
          *  #   Multiply them together: [a*b,b*c,c*a]
           O #  Sum this list: ab+bc+ca
       }K    # After the map: remove all those non-idoneal numbers from the [1,2000] list
             # (after which the result is output implicitly)
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 17 bytes
```
Ṡ-omoΣSz*ṙ1Ṗ3ḣ□43
```
[Try it online!](https://tio.run/##ASQA2/9odXNr///huaAtb21vzqNTeirhuZkx4bmWM@G4o@KWoTQz//8 "Husk – Try It Online")
Returns all idoneal numbers in ascending order, but too inefficiently to run in <1min on TIO.  
Instead, [try idoneal numbers less than 100 without timing-out](https://tio.run/##ASQA2/9odXNr///huaAtb21vzqNTeirhuZkx4bmWM@G4o@KWoTEw//8)
```
             ḣ□43   # 1..1849 (square of 43)
Ṡ-                  # return those that aren't
  omoΣ              # sums of
      Sz*           # zipping together by multiplying       
           Ṗ3       # all combinations of picking 3 numbers
         ṙ1         # with that combination rotated by 1
```
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 52 bytes
```
f()=[n|n<-[1..7!],![c-2|c<-quadclassunit(-4*n).cyc]]
```
[Try it online!](https://tio.run/##K0gsytRNL/j/P01D0zY6rybPRjfaUE/PXDFWRzE6WdeoJtlGt7A0MSU5J7G4uDQvs0RD10QrT1MvuTI5NvZ/QVFmXokGUKvmfwA "Pari/GP – Try It Online")
]