[Question]
  [
# Let's talk about divisors...
Leaving out perfect squares (for a moment), all positive integers can be expressed as the **product** of 2 of their divisors. Quick example for `126`: Here are all the divisors of `126`  
[![enter image description here](https://i.stack.imgur.com/GI2NM.jpg)](https://i.stack.imgur.com/GI2NM.jpg)
As you can see all the divisors can be paired. Here are what we will call the **Divisor Pairs**:  
`[1, 126], [2, 63], [3, 42], [6, 21], [7, 18], [9, 14]`
For this challenge we will need only the **last pair of this list** (which is the **center pair** of the picture):  
`[9,14]`.We will call this pair the **MaxMin Divisor Pair**.  
The **Difference of MaxMin Divisor Pair** **(DMDP)** is the difference of the two elements of the pair which is `[9,14]=5`  
One more example for `544`. The divisors are:
> 
> [1, 2, 4, 8, 16, **17, 32**, 34, 68, 136, 272, 544]
> 
> 
> 
and **DMDP(544)=15** because `32-17=15`
What about the **perfect squares**? All perfect squares have **DMDP=0**  
Let's take for example `64` with divisors
> 
> {1, 2, 4, **8**, 16, 32, 64}
> 
> 
> 
As you can see in this case the **MaxMin Divisor Pair** is `[8,8]` which has `DMDP=0`  
we are almost done..
# The Challenge
Given an integer `n>0`, output **how many integers less than or equal to** `10000`, **have DMDP less than** `n`
# Test Cases
***input -> output***
```
1->100 (those are all the perfect squares)
5->492  
13->1201
369->6175  
777->7264  
2000->8478  
5000->9440  
9000->9888  
10000->10000   
20000->10000
  
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'").Shortest answer in bytes **wins**.
  
[Answer]
## JavaScript (ES7), 60 bytes
```
f=(n,i=1e4,j=i**.5|0)=>i?i%j?f(n,i,j-1):(i/j-j<n)+f(n,i-1):0
```
Probably exceeds your recursion limit, so you might prefer the iterative version for 70 bytes:
```
n=>[...Array(1e4)].map(g=(j=++i**.5|0)=>i%j?g(j-1):k+=i/j-j<n,i=k=0)|k
```
[Answer]
# Java 8, ~~151~~ ~~111~~ ~~110~~ ~~101~~ 98 bytes
```
n->{int r=0,x=10000,i;for(;x-->0;r-=i-n>>-1)for(i=x;i-->1&&(x<i*i|x%i>0||(i=x/i-i)>i););return r;}
```
-10 bytes thanks to *@Nevay*.  
-3 bytes thanks to *@ceilingcat*.
**Explanation:**
[Try it here.](https://tio.run/##jZFRT8MgFIXf@yvuiwuYUYuLNguWf@Be9mh8QNaZO7vbhtKlZu1vr7Tu1SABEs75knOAk7kYUTclnQ5fk61M28KrQbomAEi@dEdjS9jNx0UAy@aduArKGFaYrTceLeyAoICJhL7OiCuydV/ILIw1qmPtmOqF0JlyokBBWgvJZxWLXmEw5GrF@he8x6G/Q50Nw@w8oECukSuuXOk7R@DUOKkkpDbdRxVSb@GXGg9wDsXZ3jukz7d3MPy39f679eU5rTufNsHyFTFKLZN8ucOf/lPEl5sIsHneRog8zyPEY3i9WM84so0jyz/9o8yNGZNx@gE)
```
n->{                  // Method with integer as parameter and return-type
  int r=0,            //  Result-integer, starting at 0
      x=10000,        //  Index-integer `x` for the outer loop, starting at 10,000
      i;              //  Index-integer `i` for the inner loop, uninitialized
  for(;x-->0;         //  Loop `x` in the range (10000, 0]:
      r-=i-n>>-1)     //   If the MaxMin-Divisor Pair's difference is lower than the input,
                      //    add 1 to the result (after every iteration)
    for(i=x;i-->1     //   Inner loop `i` in the range (`x`, 1]:
        &&(x<i*i      //    If the current square of `i` is smaller than or equals to `x`,
           |x%i>0     //    and the current `x` is divisible by `i`:
           ||(i=x/i-i)//     Calculate the MaxMin-Division difference
             >i););   //     And stop the inner loop
  return r;}          //  After the loops, return the result
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 13 bytes
1 byte thanks to Jonathan Allan.
```
ȷ4RÆDạU$Ṃ€<⁸S
```
[Try it online!](https://tio.run/##ASUA2v9qZWxsef//yLc0UsOGROG6oVUk4bmC4oKsPOKBuFP///8yMDAw "Jelly – Try It Online")
[Answer]
# [R](https://www.r-project.org/), 73 ~~77~~ bytes
Thanks to @Guiseppe for the 4 bytes
```
sum(sapply(1:1e4,function(x)min(abs((w=which(x%%1:x<1))-rev(w))))<scan())
```
[Try it online!](https://tio.run/##DcFRCoAgEAXA0whvoUChfsQOY2IopIlm2umtmTxGqQFFp3S@EFLYZTpqNLe/IjoFH6H3ArStOW8cOmNCdiWI5mwfNPqpYnQE0Vg55@MD "R – Try It Online")
Have lost the vectorize function to calculate the DMDP and is now using a sapply over the function. The truthies for items which are less than the input are summed for the result.
[Answer]
# Mathematica, 64 bytes
```
Count[Divisors~Array~1*^4,a_/;#+a[[i=⌈Tr[1^a]/2⌉]]>a[[-i]]]&
```
[Try it on Wolfram Sandbox](https://sandbox.open.wolframcloud.com)
## Usage
```
f = Count[Divisors~Array~1*^4,a_/;#+a[[i=⌈Tr[1^a]/2⌉]]>a[[-i]]]&
```
 
```
f[1]
```
> 
> 
> ```
> 100
> 
> ```
> 
> 
```
f /@ {1, 5, 13, 369, 777, 2000, 5000, 9000, 10000, 20000}
```
> 
> 
> ```
> {100, 492, 1201, 6175, 7264, 8478, 9440, 9888, 10000, 10000}
> 
> ```
> 
> 
## Explanation
```
Divisors~Array~1*^4
```
Generate the lists of divisors, from `1` to `10000`. (the lists of divisors are sorted automatically)
```
Count[ ..., a_/; ... ]
```
Count the occurrences of elements `a`, such that...
```
#+a[[i=⌈Tr[1^a]/2⌉]]>a[[-i]]]
```
`(input) + (left one of the middle element(s)) > (right one of the middle element(s))`  If there is only one middle element, left = right.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~19~~ ~~18~~ ~~17~~ ~~16~~ ~~15~~ 12 bytes
```
4°ƒNÑÂα{нI‹O
```
[Try it online!](https://tio.run/##ASEA3v8wNWFiMWX//zTCsMaSTsORw4LOsXvQvUnigLlP//83Nzc "05AB1E – Try It Online")
**Explanation**
```
4°ƒ            # for N in [0 ... 10**4] do:
   NÑ          # push divisors of N 
     Â         # bifurcate
      α        # element-wise absolute difference
       {       # sort
        н      # pop the head (smallest difference)
         I‹    # is it smaller than the input?
           O   # sum the stack
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 20 bytes
```
1e4:"@Z\2Y"dJ2/)G<vs
```
The code times out in TIO. Here's an example run with the offline compiler:
```
>> matl 1e4:"@Z\2Y"dJ2/)G<vs
> 13
1201
```
[Answer]
# [R](https://www.r-project.org/), 91 bytes
```
function(n)sum(sapply(1:1e4,function(x,d=(1:x)[x%%1:x<1])diff(d[median(seq(d))+.5*0:1]))<n)
```
Takes a different (worse) approach to computing the DMDP than [MickyT's solution](https://codegolf.stackexchange.com/a/141007/67312) by using array indexing and `diff` to compute it. Alas.
[Try it online!](https://tio.run/##PclBCoMwEEbhvfcQ5q@hJFA3Yk4iXUgnA4E6VaOQnj5m5erB@/YivsipnyP@lBTpXCjN6/r9kxtceJnbsmFfX8aU27Z2dG9wFCGelsBxVkphIwa6Z/@wQ1WMiiLk0Aj11lqUCw "R – Try It Online")
[Answer]
# Mathematica, ~~119~~ 115 bytes
```
(n=#;Tr[1^Select[Last@#-First@#&/@(Take[Divisors@#,Round[{-.1,.1}+(1+Length@Divisors@#)/2]]&/@Range@10000),#<n&]])&
```
I *finally* got this thing working and I've been trying for the past half an hour. .\_.
## Example run
[![no description for you!](https://i.stack.imgur.com/atqki.png)](https://i.stack.imgur.com/atqki.png)
[Answer]
# Mathematica, 78 bytes
```
(s=#;Tr[1^Select[Table[#2-#&@@Quantile[Divisors@i,{.5,.51}],{i,10^4}],#<s&]])&
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 19 bytes
```
#ȯV<⁰Sz≠↔§f`¦ḣḣ□100
```
No TIO link, since it times out.
[This version](https://tio.run/##yygtzv7/X/nE@jCbR40bgqsedS541Dbl0PK0hEPLHu5YDESGBgb///83BAA "Husk – Try It Online") uses 100 in place of 10000 and finishes in a couple of seconds.
## Explanation
Husk has no divisors built-in or support for scientific notation yet.
```
#ȯV<⁰Sz≠↔§f`¦ḣḣ□100  Input is n (accessed with ⁰).
               □100  Square of 100: 10000
              ḣ      Inclusive range from 1.
#                    Count number of elements for which
 ȯ                   this composition of 3 functions gives truthy result:
                       Argument k, say k = 12.
         §f`¦ḣ         Divisors of k:
             ḣ           Range: [1,2,3,..,12]
         §f              Filter by
           `¦            divides k: [1,2,3,4,6,12]
     Sz≠↔              Absolute differences of divisor pairs:
        ↔                Reverse: [12,6,4,3,2,1]
     Sz                  Zip with divisor list
       ≠                 using absolute difference: [11,4,1,1,4,11]
  V<⁰                  Is any of these less than n?
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt/), ~~25~~ ~~19~~ 17 bytes
```
L²õÈâ ®aX/ZÃd<UÃè
```
[Test it](https://ethproductions.github.io/japt/?v=1.4.5&code=TLL1yOIgrmFYL1rDZDxVw+g=&input=MTM=)
---
## Explanation
Implicit input of integer `U`.
```
L²õ
```
Generate an array of integers (`õ`) from 1 to 100 (`L`) squared.
```
Èâ          Ã
```
Pass each through a function (where `X` is the current element) that generates an array of the divisors (`â`) of `X`.
```
®    Ã
```
Map over that array of divisors, where `Z` is the current element.
```
aX/Z
```
Get the absolute difference (`a`) of `Z` and `X` divided by `Z`.
```
d<U
```
Are any of the elements (`d`) in the resulting array less than `U`?
```
è
```
Count the truthy elements and implicitly output the result.
[Answer]
# Ruby, 62 bytes
```
->n{(1..1e4).count{|x|(1..x).any?{|i|1>x%i&&x/i<=i&&i-x/i<n}}}
```
[Try it online.](https://tio.run/##KypNqvyfZvtf1y6vWsNQT88w1URTLzm/NK@kuqaiBiRSoamXmFdpX12TWWNoV6GaqaZWoZ9pYwukM3VBrLza2tr/BaUlxQpp0aYGBgax/wE)
[Answer]
# TI-BASIC, 46 bytes
Note that TI-BASIC is a tokenized language. Also, the E in line 2 is a small capital E, found by pressing 2ND+, .
```
Input A
DelVar DFor(B,1,E4
For(C,1,√(B
If not(fPart(B/C
B/C-C<A
End
D+Ans→D
End
```
Result will be in D, and Ans immediately after program execution. If it is to be displayed, adding two more bytes (newline and `Ans`) would suffice.
[Answer]
# [Python 2](https://docs.python.org/2/), 134 bytes
```
lambda i:len(filter(lambda n:n<i,[reduce(lambda x,y:y-x,[[x,n/x]for x in range(1,int(n**.5+1))if n%x<1][-1])for n in range(1,10001)]))
```
[Try it online!](https://tio.run/##TY5BDsIgEEX3nmI2JqCjgkabEj0JsqgKSlKnDcWEnr6Wqombv3jz/s@0fXw0tB3c6TzU1fNyq8Cr2hJzvo42sC8jRUePOtjb62p/MGGv@lVCrRPSJhnXBEjgCUJFd8skeoqMFov1fik59w5ono7S6JU0PLv070ohhOSG8yHaLnZwAi0R9ghyh7A7lAhFUSBsR23EU5ZT5qL4HISZzfKwz8PTjII2jF@AY54Pbw "Python 2 – Try It Online")
Eugh... need to do *much* better.
[Answer]
# [Python 2](https://docs.python.org/2/), 83 bytes
A bit on the slow side, uses 5 seconds per test case 
```
lambda x:sum(x>min(abs(y/t-t)for t in range(1,y+1)if y%t<1)for y in range(1,10001))
```
[Try it online!](https://tio.run/##TY1dC4IwFIav81ecm2CjE22KiZL9kYqY5WqQU9wJ3K9fTejj5r143q/B0723adD1MTxU11wVTJV7dmzad8Yy1TjmN7QmrvsRCIyFUdlbyyT6leRGg1/STs6u/3elEEJyHqh1dL4o1zqo4SAxR5lhti2xKApM3yHMo5RRYkfMUJyS@e9Tjsu/pSpZDKOxBJp9IQ8v)
[Answer]
# PHP, 94+1 bytes
```
for(;$n++<1e4;$c+=$d<$argn)if(($i=$n**.5)>~~$i){while($n%++$i);for($d=1;$n%--$i;)$d++;}echo$c;
```
Run as pipe with `-nR` or [try it online](http://sandbox.onlinephpfunctions.com/code/d29d5bceac53b3881f2eed6e7006def821897f88).
[Answer]
# VB.NET (.NET 4.5) ~~116~~ 115 bytes
```
Function A(n)
For i=1To 10^4
Dim s As Byte=Math.Sqrt(i)
While i Mod s>0
s-=1
End While
A-=i/s-s<n
Next
End Function
```
---
Explanation:
A function that takes `n` as a parameter, and returns the result.
Starts at the square root, and looks for the nearest integer that evenly divides (will be the smaller of the `MaxMin Divisor Pair`). Then gets the larger of the pair (`i/s`), finds the difference, and compares against the input.
---
Golfing strategies used:
* `Dim` is expensive, so the fewer variables I declare the better.
* I start searching at the square root, but only want to look at integers. By declaring `s` as an integral type, it casts to the floor for me.
* VB uses `^` as exponent. So while `10000` is 5 characters, `10^4` is only 4.
* VB creates an automatic variable with the same name and type as the function definition (in my case A). At the end of the function, if there is no `return`, the value of the function variable will be returned instead. So I save characters by not declaring a separate variable and not using a return statement.
* VB has very forgiving typing/casting. `i` is assumed `Integer` because I assigned a integer literal. `A` is assumed `Object` but as soon as I add an integer, it behaves like an `Integer`.
* Rather than `if` checking the that the difference is satisfactory, add it directly to the result by casting the boolean to an integer. However, VB uses `-1` for `True`, so subtract to get the correct sign.
* Technically, we want `Mod` to not be `0`. Taking the modulus of a negative number in VB.NET will give a negative result. But, everything is positive so I can save a byte by turning `<>` into `>`.
* The largest number to check is 10000. The square root of that is 100. So I only need a `Byte` to store that, saving bytes in the declaration by using a shorter named type.
[Try it online!](https://tio.run/##fdE9b8MgEAbgnV9xW82AC01SK1JdyW2Tqc6SSNkqEfvUnOSAArgfv97FVN1qszA8d7yn44N8rztx0p4aYTCIizV2qG3bdwg1e6ELEGgPZAK@o4MbqGMBOLz25NBDi02nnQ5kjYfPM8WufLc5wDJfQWtjgbFh2PamGSugygxnW@uASnWwoOTbMkV4qDw8fQcsax3O@f7qQkacHdN7FCNb8I@SeVEqtjEtJGCVKOnWC/9g2A6/QpK/qGHfn6DWZBh7jqPZDvOjo4CvZDCrMsUhHv6vrWZMLfikLe7XfMqKopi0Oykln5plxtYzpuSI03mjsbSwuKd0/3758AM)
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 104 bytes
```
x=>{int o=0,i=1;for(;i<=10000;i++)for(int j=1;j<=i;j++)if(i%j<1&Math.Abs(j-i/j)<x){o++;break;}return o;}
```
[Try it online!](https://tio.run/##fdFBS8MwFAfws/0UYag0dJ3NSi0lTUEETw4GHjyIh6ym89WZQJLKpPSz17Rz4EGSQ/J4@RH@SWoT10qLsTMg9@jp21jxSYP6wI1B2z4wlluo0UMn6xKkXSI3VQ0bj6zqXYkUS5bACG2UDimUjCRuUIgiPHUm0brdtmRAW9eEJoSrtiTXG27fV3c7E7Yx3LS4POJeRRHdacE/6KCF7bREig4jPUf4UvCGNhxkaKx2WV9eEdd7g/vg4l5Jow5i9azBikeQIrxckLjqm5DgYYHp/yKbReYRJD0dknpMelvMyK0elef5rNzqUWv3djObCl/ys8v8rji7wu/mTztdNfHLdfI34q8cgmH8AQ "C# (.NET Core) – Try It Online")
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 52 bytes
```
Boole@Array[AtomQ@√(4a+#^2)&,#,0,Or]~Sum~{a,1*^4}&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b73yk/PyfVwbGoKLEy2rEkPzfQ4VHHLA2TRG3lOCNNNR1lHQMd/6LYuuDS3LrqRB1DrTiTWrX/AUWZeSXRyrp2aQ7KsWp1wcmJeXXVXIY6XKY6XIbGOlzGZpY6XObm5jpcRgYGBkBhMGkJJg0NwBRIwoCr9j8A "Wolfram Language (Mathematica) – Try It Online")
Slow.
]