[Question]
  [
A positive integer *n* can be represented as a *rectangle with integer sides* *a*, *b* such that *n* = *a* \* *b*. That is, the area represents the number. In general, *a* and *b* are not unique for a given *n*.
As is well known, a rectangle is specially pleasing to the eye (or is it the brain?) when its sides are in the [*golden ratio*](https://en.wikipedia.org/wiki/Golden_ratio), *φ* = (sqrt(5)+1)/2 ≈ 1.6180339887...
Combining these two facts, the purpose of this challenge is to decompose an integer *n* into the product of two integers *a*, *b* whose ratio is as close as possible to *φ* (with the usual metric on ℝ). The fact that *φ* is irrational implies that there is a unique solution pair (*a*, *b*).
# The challenge
Given a positive integer *n*, output positive integers *a*, *b* such that *a* \* *b* = *n* and the absolute difference between *a*/*b* and *φ* is minimized.
As an example, consider *n* = 12. The pairs (*a*, *b*) that satisfy *a* \* *b* = *n* are: (1, 12), (2,6), (3,4), (4,3), (6,2), (12,1). The pair whose ratio is closest to *φ* is (4,3), which gives 4/3 = 1.333.
# Rules
Functions or programs are acceptable.
The *numerator* (*a*) should appear *first* in the output, and the *denominator* (*b*) *second*. Other than that, input and output formats are flexible as usual. For example, the two numbers can be output as strings with any reasonable separator, or as an array.
The code should work in theory for arbitrarily large numbers. In practice, it may be limited by memory or data-type restrictions.
It's sufficient to consider an approximate version of *φ*, as long as it is accurate up to the *third decimal* or better. That is, the absolute difference between the true *φ* and the approximate value should not exceed 0.0005. For example, 1.618 is acceptable.
When using an approximate, rational version of *φ* there's a small chance that the solution is not unique. In that case you can output any pair *a*, *b* that satisfies the minimization criterion.
Shortest code wins.
# Test cases
```
1        ->  1    1
2        ->  2    1 
4        ->  2    2
12       ->  4    3
42       ->  7    6
576      ->  32   18
1234     ->  2    617
10000    ->  125  80
199999   ->  1    199999
9699690  ->  3990 2431
```
  
[Answer]
# Pyth - ~~24~~ 23 bytes
There has to be a better way to find the divisors...
```
ho.a-.n3cFNfsIeTm,dcQdS
```
[Test Suite](http://pyth.herokuapp.com/?code=ho.a-.n3cFNfsIeTm%2CdcQdS&test_suite=1&test_suite_input=1%0A2%0A4%0A12%0A42%0A576%0A1234%0A10000%0A199999&debug=0).
[Answer]
# Jelly, ~~16~~ ~~15~~ 14 bytes
*Saved 1 byte thanks to @miles.*
```
÷/ạØp
ÆDżṚ$ÇÞḢ
```
[Try it online!](http://jelly.tryitonline.net/#code=w7cv4bqhw5hwCsOGRMW84bmaJMOHw57huKI&input=&args=OTY5OTY5MA)
### Explanation
```
÷/ạØp         Helper link, calculates abs(a/b - phi). Argument: [a, b]
÷/            Reduce by division to calculate a/b.
  ạØp         Calculate abs(a/b - phi).
ÆDżṚ$ÇÞḢ      Main link. Argument: n
ÆD            Get divisors of n.
  żṚ$         Pair the items of the list with those of its reverse. The reversed
              divisors of a number is the same list as the number divided by each
              of the divisors.
     ÇÞ       Sort by the output of the helper link of each pair.
       Ḣ      Get the first element [a, b] and implicitly print.
```
[Answer]
# Matlab, 96 81 bytes
Golfed (-15bytes), props to [Luis Mendo](https://codegolf.stackexchange.com/users/36398/luis-mendo)
```
function w(n);a=find(~(mod(n,1:n)));[~,c]=min(abs(a./(n./a)-1.618));[a(c) n/a(c)]
```
Original:
```
function w(n)
a=find(not(mod(n,1:n)));b=abs(a./(n./a)-1.618);c=find(not(b-min(b)));[a(c) n/a(c)]
```
This is by far not a great solution, but my first attempt at code-golf. What fun!
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), 21 bytes
Code:
```
ÑÂø©vy`/})5t>;-ÄWQ®sÏ
```
Uses the **CP-1252** encoding. [Try it online!](http://05ab1e.tryitonline.net/#code=w5HDgsO4wql2eWAvfSk1dD47LcOEV1HCrnPDjw&input=MTAwMDA)
[Answer]
## Mathematica, 51 bytes
```
#&@@SortBy[{x=Divisors@#,#/x},Abs[#/#2-1.618]&]&
```
The `` is Mathematica's postfix operator for transposition (displayed as a superscript `T` in Mathematica).
Mathematica has a built-in `GoldenRatio`, but 1.618 is a lot shorter, especially because the former also requires `N@`.
[Answer]
# Pyth, ~~21~~ ~~20~~ 18 bytes
```
hoacFN.n3C_Bf!%QTS
```
[Try it online.](http://pyth.herokuapp.com/?code=hoacFN.n3C_Bf!%25QTS&input=125&debug=0) [Test suite.](http://pyth.herokuapp.com/?code=hoacFN.n3C_Bf!%25QTS&test_suite=1&test_suite_input=1%0A2%0A4%0A12%0A42%0A576%0A1234%0A10000%0A199999&debug=0)
### Explanation
1. Get the inclu`S`ive range from 1 to input.
2. `f`ilter for numbers for that divide the input `!%QT`.
3. Get `[that list, that list reversed]` `_B`. The reversed divisors of a number is the same list as the number divided by each of the divisors.
4. Transpose the list to get pairs of `[numerator, denominator]`.
5. S`o`rt the pairs by the `a`bsolute difference of the ratio of the pair `cFN` and the golden ratio `.n3`.
6. Get the first (lowest) pair `h` and print.
[Answer]
## Javascript (ES6), 73 bytes
```
n=>{for(b=0,k=n/.809;n%++b||k>b*b*2&&(a=b););return[b=k-a*a>b*b?b:a,n/b]}
```
We look for:
* **a** = highest divisor of n for which **n / φ > a²**
* **b** = lowest divisor of n for which **n / φ < b²**
Then, the solution is either **[ a, n / a ]** or **[ b, n / b ]**. We compare **n / φ - a²** with **b² - n / φ** to find out which expression is closest to zero.
The actual formula used in the code are based on φ / 2 which can be written in a shorter way than φ with the same precision: `.809` vs `1.618`.
Therefore:
> 
> n / φ > a² ⇔ **n / (φ / 2) > 2a²**
> 
> 
> 
and:
> 
> n / φ - a² > b² - n / φ ⇔ 2n / φ - a² > b² ⇔ **n / (φ / 2)
>  - a² > b²**
> 
> 
> 
### Complexity
The number of iterations heavily depends on the number of factors of n. The worst case occurs when n is prime, because we have to perform all iterations from 1 to n to find its only 2 divisors. This is what happens with 199999. On the other hand, 9699690 is 19-smooth and we quickly find two divisors on either sides of the breaking point √(n/φ) ≈ 2448.
### Test cases
```
let f =
n=>{for(b=0,k=n/.809;n%++b||k>b*b*2&&(a=b););return[b=k-a*a>b*b?b:a,n/b]}
console.log(JSON.stringify(f(12)));       // [ 3, 4 ]
console.log(JSON.stringify(f(42)));       // [ 6, 7 ]
console.log(JSON.stringify(f(576)));      // [ 18, 32 ]
console.log(JSON.stringify(f(1234)));     // [ 2, 617 ]
console.log(JSON.stringify(f(10000)));    // [ 80, 125 ]
console.log(JSON.stringify(f(199999)));   // [ 1, 199999 ]
console.log(JSON.stringify(f(9699690)));  // [ 2431, 3990 ]
```
[Answer]
## JavaScript (ES6), 83 bytes
```
f=
n=>{p=r=>Math.abs(r/n-n/r-1);for(r=i=n;--i;)r=n%i||p(i*i)>p(r*r)?r:i;return[r,n/r]}
;
```
```
<input type=number min=1 oninput=[a.value,b.value]=f(+this.value)><input readonly id=a><input readonly id=b>
```
Actually returns the (*a*, *b*) pair which minimises the absolute value of *a*/*b*-*b*/*a*-1, but this works for all the test cases at least, although I guess I could save 4 bytes by using the 1.618 test instead.
[Answer]
# [Brachylog](http://github.com/JCumin/Brachylog), 41 bytes
```
:1fL:2a:Lzoht
,A:B#>.*?!,.=
:3a/:$A-$|
//
```
[Try it online!](http://brachylog.tryitonline.net/#code=OjFmTDoyYTpMem9odAosQTpCIz4uKj8hLC49CjozYS86JEEtJHwKLy8&input=NTc2&args=Wg)
### Explanation
* Main predicate:
```
:1fL           L is the list of all couples [A:B] such that A*B = Input (see Pred. 1)
    :2a        Compute the distance between all As/Bs and φ (see Pred. 2)
       :Lz     Zip those distances to L
          o    Sort the zip on the distances
           ht  Take the couple [A:B] of the first element of the sorted list
```
* Predicate 1: Output is a couple `[A:B]` such that `A*B = Input`
```
,A:B           The list [A:B]
    #>         Both A and B are strictly positive
      .        Output = [A:B]
       *?      A*B = Input
         !,    Discard other choice points
           .=  Assign a value to A and B that satisfy the constraints
```
* Predicate 2: Compute the distance between `A/B` and φ.
```
:3a            Convert A and B to floats
   /           Divide A by B
    :$A-       Subtract φ
        $|     Absolute value
```
* Predicate 3: Convert an int to a float by inverting its inverse
```
/              1/Input
 /             Output = 1/(1/Input)
```
[Answer]
# Haskell (Lambdabot), 86 bytes
```
f(x,y)=abs$(x/y)-1.618
q n=minimumBy((.f).compare.f)[(x,y)|x<-[1..n],y<-[1..n],x*y==n]
```
[Answer]
# php, 103 bytes
```
<?php for($s=$a=$argv[1];++$i<$a;)if($a%$i==0&&$s>$t=abs($i*$i/$a-1.618)){$n=$i;$s=$t;}echo"$n ".$a/$n;
```
Produces a notice (this doesn't interrupt execution) about unassigned $i so should be run in an environment that silences notices.
[Answer]
# Python 3, 96 bytes
Pretty simple solution. Makes use of [this SO answer](https://stackoverflow.com/a/5505024/2415524).
```
lambda n:min([((i,n//i),abs(1.618-i/(n//i)))for i in range(1,n+1)if n%i<1],key=lambda x:x[1])[0]
```
[**Try it online**](https://repl.it/D6Gh)
The same solution in Python 2 is one byte longer.
```
lambda n:min([((i,n/i),abs(1.618-1.*i/(n/i)))for i in range(1,n+1)if n%i<1],key=lambda x:x[1])[0]
```
]