Skip to main content
Computation update
Source Link
S. Carnahan
  • 45.7k
  • 6
  • 114
  • 220

First, I'd like to revisit Will Sawin's upper bound, but I make no promises about off-by-one errors (which I think I made in comments elsewhere on this page). The product of any sequence of $x$ consecutive integers has $p$-valuation at least $\lfloor \frac{x}{p-1}\rfloor - \lfloor \log_p(x+1) \rfloor$. The $p$-valuation of $\binom{n}{a}$ is the number of carries when adding $a$ to $n-a$ in base $p$, so this is bounded above by $\lfloor \log_p n \rfloor$. In other words, the product of the $x = b-(n-a)$$v = b-(n-a)$ integers from $n-a+1$ to $b$ must satisfy $\lfloor \frac{x}{p-1}\rfloor - \lfloor \log_p(x+1) \rfloor \leq \lfloor \log_p n \rfloor$$\lfloor \frac{v}{p-1}\rfloor - \lfloor \log_p(v+1) \rfloor \leq \lfloor \log_p n \rfloor$. Pushing some terms around yields the bound $$x \leq (p-1)\lfloor log_p(n) \rfloor +(p-1) \lfloor log_p log_p n \rfloor + 2p - 2.$$ If$$v \leq (p-1)\lfloor log_p(n) \rfloor +(p-1) \lfloor log_p log_p n \rfloor + 2p - 2.$$

In particular, $v \leq \lfloor log_2(n) \rfloor + \lfloor log_2 log_2 n \rfloor$. If we only worry about making $\frac{n!}{a!b!}$ into a 2-adic integer instead of an ordinary integer, then this bound is sharp, since the case $n=2^k, a=2^k-1, b = 2^y-1$ saturates it when $k = 2^y-y-1$.

Incidentally, there are infinitely many integers $n$ for which the virtue $v = a+b-n$ is bounded above by 1. In particular, any Mersenne number $n = 2^k-1$ satisfies $\binom{n}{a} \equiv 1 \pmod 2$, so we get a 2-adic obstruction to larger virtue.

When $n$ is large, $(p-1) \lfloor \log_p(n) \rfloor > \lfloor \log_2(n) \rfloor$ for odd $p$, so this suggests that it is good to check 2-valuationsadic valuations when eliminating candidate triples. By request, here is some computer code.

Edit: Following Following Noam D. Elkies's suggestion, I rewrote my program in C. Also, I found an overflow bug in my valuation routine, as a result of using 32 bit integers and multiplying unnecessarily, so some of the previous results for $n>65536$ were false. You can find the original SAGE code by looking at the edit history of this answer. Since the C code is somewhat longer than the SAGE version, I put it here on my web page.

Anyway, starting with k=3 and running up to $2^{23} = 8388608$$2^{25} = 33554432$ took about 348 hours on a 12-core desktop. Here are the results in the form $a, b, n, k$$a, b, n, v$:

3, 5, 6, 2
6, 7, 10, 3
11, 29, 36, 4
14, 47, 56, 5
47, 59, 100, 6
59, 110, 162, 7
23, 241, 256, 8
31, 239, 261, 9
187, 239, 416, 10
447, 620, 1056, 11
239, 1853, 2080, 12
1439, 1775, 3201, 13
1663, 2735, 4384, 14
14335, 18458, 32778, 15
9209, 23615, 32808, 16
13106, 52447, 65536, 17
26207, 39347, 65536, 18
34719, 227444, 262144, 19
109237, 152927, 262144, 20
59039, 465398, 524416, 21
230111, 294839, 524928, 22
496123, 3698204, 4194304, 23
1007871, 3186457, 4194304, 24
983546, 7405087, 8388608, 25
1029947, 7358687, 8388608, 26
527036, 33027423, 33554432, 27
2479487, 31074973, 33554432, 28

I checked aThe last few largerentries are reasonable evidence that I don't lose much by only considering powers of two when computing optimal virtue. I computed up to $n=2^{39} = 549755813888$, and have $n=2^{40}$ in progress - here arethis last computation will take about 42 hours. Unlike the maximal values ofprevious case, I didn't bother to precompute valuations, due to memory constraints. Code is here $a+b-n$:- it has no input checks, so bad inputs will produce a segfault.

2, 3, 4, 1
2, 7, 8, 1
5, 14, 16, 3
9, 26, 32, 3
19, 49, 64, 4
17, 116, 128, 5
23, 241, 256, 8
53, 467, 512, 8
314, 719, 1024, 9
482, 1574, 2048, 8
1943, 2164, 4096, 11
1979, 6227, 8192, 14
3317, 13081, 16384, 14
6548, 26234, 32768, 14
26207, 39347, 65536, 18
56375, 74354, 131072, 17
109237, 152927, 262144, 20
58559, 465749, 524288, 20
117350, 931247, 1048576, 21
511613, 1585561, 2097152, 22
1007871, 3186457, 4194304, 24
1029947, 7358687, 8388608, 26
839773, 15937469, 16777216, 26
2479487, 31074973, 33554432, 28
28499711, 38609183, 67108864, 30
13640318, 120577439, 134217728, 29
26335607, 242099879, 268435456, 30
149450463, 387420479, 536870912, 30
42571871, 1031169982, 1073741824, 30
210421817, 1937061863, 2147483648, 32
808182959, 3486784371, 4294967296, 34
66684221, 8523250405, 8589934592, 34
57373109, 17122496111, 17179869184, 36
1071383543, 33288354863, 34359738368, 38
194490575, 68524986199, 68719476736, 38
722568911, 136716384599, 137438953472, 38
2908726651, 27196918033, 274877906944, 40
5820696123, 543935117807, 549755813888, 42
275025321599, 824486306219, 1099511627776, 42 (?)

The optimal virtue for $n=2^k$ hews quite close to the 2-adic upper bound, but some kind of strong height result would be necessary to find enough structure in the solutions to get a guaranteed lower bound for large $n$.

First, I'd like to revisit Will Sawin's upper bound, but I make no promises about off-by-one errors (which I think I made in comments elsewhere on this page). The product of any sequence of $x$ consecutive integers has $p$-valuation at least $\lfloor \frac{x}{p-1}\rfloor - \lfloor \log_p(x+1) \rfloor$. The $p$-valuation of $\binom{n}{a}$ is the number of carries when adding $a$ to $n-a$ in base $p$, so this is bounded above by $\lfloor \log_p n \rfloor$. In other words, the product of the $x = b-(n-a)$ integers from $n-a+1$ to $b$ must satisfy $\lfloor \frac{x}{p-1}\rfloor - \lfloor \log_p(x+1) \rfloor \leq \lfloor \log_p n \rfloor$. Pushing some terms around yields the bound $$x \leq (p-1)\lfloor log_p(n) \rfloor +(p-1) \lfloor log_p log_p n \rfloor + 2p - 2.$$ If we only worry about making $\frac{n!}{a!b!}$ into a 2-adic integer instead of an ordinary integer, then this bound is sharp, since the case $n=2^k, a=2^k-1, b = 2^y-1$ saturates it when $k = 2^y-y-1$.

When $n$ is large, $(p-1) \lfloor \log_p(n) \rfloor > \lfloor \log_2(n) \rfloor$ for odd $p$, so this suggests that it is good to check 2-valuations when eliminating candidate triples. By request, here is some computer code.

Edit: Following Noam D. Elkies's suggestion, I rewrote my program in C. Also, I found an overflow bug in my valuation routine, as a result of using 32 bit integers, so some of the previous results for $n>65536$ were false. Since the C code is somewhat longer than the SAGE version, I put it here on my web page.

Anyway, starting with k=3 and running up to $2^{23} = 8388608$ took about 3 hours on a 12-core desktop. Here are the results in the form $a, b, n, k$:

3, 5, 6, 2
6, 7, 10, 3
11, 29, 36, 4
14, 47, 56, 5
47, 59, 100, 6
59, 110, 162, 7
23, 241, 256, 8
31, 239, 261, 9
187, 239, 416, 10
447, 620, 1056, 11
239, 1853, 2080, 12
1439, 1775, 3201, 13
1663, 2735, 4384, 14
14335, 18458, 32778, 15
9209, 23615, 32808, 16
13106, 52447, 65536, 17
26207, 39347, 65536, 18
34719, 227444, 262144, 19
109237, 152927, 262144, 20
59039, 465398, 524416, 21
230111, 294839, 524928, 22
496123, 3698204, 4194304, 23
1007871, 3186457, 4194304, 24
983546, 7405087, 8388608, 25
1029947, 7358687, 8388608, 26

I checked a few larger powers of two - here are the maximal values of $a+b-n$:

2, 3, 4, 1
2, 7, 8, 1
5, 14, 16, 3
9, 26, 32, 3
19, 49, 64, 4
17, 116, 128, 5
23, 241, 256, 8
53, 467, 512, 8
314, 719, 1024, 9
482, 1574, 2048, 8
1943, 2164, 4096, 11
1979, 6227, 8192, 14
3317, 13081, 16384, 14
6548, 26234, 32768, 14
26207, 39347, 65536, 18
56375, 74354, 131072, 17
109237, 152927, 262144, 20
58559, 465749, 524288, 20
117350, 931247, 1048576, 21
511613, 1585561, 2097152, 22
1007871, 3186457, 4194304, 24
1029947, 7358687, 8388608, 26
839773, 15937469, 16777216, 26
2479487, 31074973, 33554432, 28
28499711, 38609183, 67108864, 30
13640318, 120577439, 134217728, 29
26335607, 242099879, 268435456, 30
149450463, 387420479, 536870912, 30
42571871, 1031169982, 1073741824, 30

First, I'd like to revisit Will Sawin's upper bound, but I make no promises about off-by-one errors (which I think I made in comments elsewhere on this page). The product of any sequence of $x$ consecutive integers has $p$-valuation at least $\lfloor \frac{x}{p-1}\rfloor - \lfloor \log_p(x+1) \rfloor$. The $p$-valuation of $\binom{n}{a}$ is the number of carries when adding $a$ to $n-a$ in base $p$, so this is bounded above by $\lfloor \log_p n \rfloor$. In other words, the product of the $v = b-(n-a)$ integers from $n-a+1$ to $b$ must satisfy $\lfloor \frac{v}{p-1}\rfloor - \lfloor \log_p(v+1) \rfloor \leq \lfloor \log_p n \rfloor$. Pushing some terms around yields the bound $$v \leq (p-1)\lfloor log_p(n) \rfloor +(p-1) \lfloor log_p log_p n \rfloor + 2p - 2.$$

In particular, $v \leq \lfloor log_2(n) \rfloor + \lfloor log_2 log_2 n \rfloor$. If we only worry about making $\frac{n!}{a!b!}$ into a 2-adic integer instead of an ordinary integer, then this bound is sharp, since the case $n=2^k, a=2^k-1, b = 2^y-1$ saturates it when $k = 2^y-y-1$.

Incidentally, there are infinitely many integers $n$ for which the virtue $v = a+b-n$ is bounded above by 1. In particular, any Mersenne number $n = 2^k-1$ satisfies $\binom{n}{a} \equiv 1 \pmod 2$, so we get a 2-adic obstruction to larger virtue.

When $n$ is large, $(p-1) \lfloor \log_p(n) \rfloor > \lfloor \log_2(n) \rfloor$ for odd $p$, so this suggests that it is good to check 2-adic valuations when eliminating candidate triples. Following Noam D. Elkies's suggestion, I rewrote my program in C. Also, I found an overflow bug in my valuation routine, as a result of using 32 bit integers and multiplying unnecessarily, so some of the previous results for $n>65536$ were false. You can find the original SAGE code by looking at the edit history of this answer. Since the C code is somewhat longer than the SAGE version, I put it here on my web page.

Anyway, starting with k=3 and running up to $2^{25} = 33554432$ took about 48 hours on a 12-core desktop. Here are the results in the form $a, b, n, v$:

3, 5, 6, 2
6, 7, 10, 3
11, 29, 36, 4
14, 47, 56, 5
47, 59, 100, 6
59, 110, 162, 7
23, 241, 256, 8
31, 239, 261, 9
187, 239, 416, 10
447, 620, 1056, 11
239, 1853, 2080, 12
1439, 1775, 3201, 13
1663, 2735, 4384, 14
14335, 18458, 32778, 15
9209, 23615, 32808, 16
13106, 52447, 65536, 17
26207, 39347, 65536, 18
34719, 227444, 262144, 19
109237, 152927, 262144, 20
59039, 465398, 524416, 21
230111, 294839, 524928, 22
496123, 3698204, 4194304, 23
1007871, 3186457, 4194304, 24
983546, 7405087, 8388608, 25
1029947, 7358687, 8388608, 26
527036, 33027423, 33554432, 27
2479487, 31074973, 33554432, 28

The last few entries are reasonable evidence that I don't lose much by only considering powers of two when computing optimal virtue. I computed up to $n=2^{39} = 549755813888$, and have $n=2^{40}$ in progress - this last computation will take about 42 hours. Unlike the previous case, I didn't bother to precompute valuations, due to memory constraints. Code is here - it has no input checks, so bad inputs will produce a segfault.

2, 3, 4, 1
2, 7, 8, 1
5, 14, 16, 3
9, 26, 32, 3
19, 49, 64, 4
17, 116, 128, 5
23, 241, 256, 8
53, 467, 512, 8
314, 719, 1024, 9
482, 1574, 2048, 8
1943, 2164, 4096, 11
1979, 6227, 8192, 14
3317, 13081, 16384, 14
6548, 26234, 32768, 14
26207, 39347, 65536, 18
56375, 74354, 131072, 17
109237, 152927, 262144, 20
58559, 465749, 524288, 20
117350, 931247, 1048576, 21
511613, 1585561, 2097152, 22
1007871, 3186457, 4194304, 24
1029947, 7358687, 8388608, 26
839773, 15937469, 16777216, 26
2479487, 31074973, 33554432, 28
28499711, 38609183, 67108864, 30
13640318, 120577439, 134217728, 29
26335607, 242099879, 268435456, 30
149450463, 387420479, 536870912, 30
42571871, 1031169982, 1073741824, 30
210421817, 1937061863, 2147483648, 32
808182959, 3486784371, 4294967296, 34
66684221, 8523250405, 8589934592, 34
57373109, 17122496111, 17179869184, 36
1071383543, 33288354863, 34359738368, 38
194490575, 68524986199, 68719476736, 38
722568911, 136716384599, 137438953472, 38
2908726651, 27196918033, 274877906944, 40
5820696123, 543935117807, 549755813888, 42
275025321599, 824486306219, 1099511627776, 42 (?)

The optimal virtue for $n=2^k$ hews quite close to the 2-adic upper bound, but some kind of strong height result would be necessary to find enough structure in the solutions to get a guaranteed lower bound for large $n$.

corrections, updates.
Source Link
S. Carnahan
  • 45.7k
  • 6
  • 114
  • 220

Edit: Following Noam D. Elkies's suggestion, I couldn't find a fast functionrewrote my program in SAGE for computing theC. Also, I found an overflow bug in my valuation ofroutine, as a factorialresult of using 32 bit integers, so I made a Cython file "valsome of the previous results for $n>65536$ were false.spyx" with Since the C code:

def val(int a, int p):
    cdef int i,r
    i=0
    r=p
    while(a >= r):
        i = i + (a/r)
        r = r*p
    return i

In is somewhat longer than the SAGE version, I compiledput it withhere on my web page.

load ".../val.spyx"

where "..Anyway, starting with k=3 and running up to $2^{23} = 8388608$ took about 3 hours on a 12-core desktop." indicates the directory holding Here are the file (available withresults in the "pwd" UNIX command). Then I wrote three functionsform (I imagine there are more elegant ways to write these)$a, b, n, k$:

def innerloop(a,b3,c):
  5, 6, r=02
 6, 7, 10, p=23
    while(r==0 and p <= min(b11,c)):
        if val(a29,p) < val(b36,p) + val(c,p):4
         14, 47, 56, r=15
     47, 59, 100, p=next_prime(p)6
  59, 110, return162, r
7
def testvirtue(m23,k):
  241, 256, r=08
    for i in range((m+k+1)/231,m):
        if innerloop(m,i239,m-i+k)==0:
            print m,i261,m-i+k
            r=19
  187, 239, return416, r
10
def testrange(m,n447,k):
    for i in range(m620,n):
        if testvirtue(i1056,k):
            k=k+111
            testvirtue(i239,k)
   1853, return2080, k12

Anyway, starting with k=3 and running up to 80000 took about 2 hours on my laptop:

10 71439, 6
361775, 233201, 1713
36 291663, 11
562735, 474384, 14
100 59 47
162 107 62
162 11014335, 59
25618458, 14232778, 12215
256 2029209, 62
25623615, 23932808, 2516
256 24113106, 23
26152447, 22365536, 4717
261 23926207, 31
41639347, 23965536, 18718
1056 62034719, 447
2080227444, 1214262144, 87819
2080 1853 239109237, 
3201152927, 1775262144, 143920
4384 273559039, 1663
32778465398, 18458524416, 1433521
32808 18617230111, 14207
32808294839, 23615524928, 920922
65536 34963496123, 30590
655363698204, 393144194304, 2623923
65536 393191007871, 26234
655363186457, 393234194304, 2623024
65536 39346983546, 26207
655367405087, 393478388608, 2620625
65536 524471029947, 13106
655367358687, 393478388608, 26207
1926

As you can see from the last entries, the optimal value of $a+b-n$ jumps by 2 to 18 at 65536. II checked a few larger powers of two beyond 80000 - here are the maximal values of $a+b-n$:

2, 3, 4, 1
2, 7, 8, 1
5, 14, 16, 3
9, 26, 32, 3
19, 49, 64, 4
17, 116, 128, 5
23, 241, 256, 8
53, 467, 512, 8
314, 719, 1024, 9
482, 1574, 2048, 8
1943, 2164, 4096, 11
1979, 6227, 8192, 14
3317, 13081, 16384, 14
6548, 26234, 32768, 14
26207, 39347, 65536, 18
56375, 74354, 131072, 17
109237, 152927, 262144, 20
58559, 465749, 524288, 20
117350, 931247, 1048576, 21
511613, 1585561, 2097152, 1222
1007871, 3186457, 4194304, 2024
1029947, 7358687, 8388608, 2026
839773, 15937469, 16777216, 2126
2479487, 31074973, 33554432, 28
28499711, 38609183, 67108864, 30
13640318, 120577439, 134217728, 29
26335607, 242099879, 268435456, 30
149450463, 387420479, 536870912, 30
42571871, 1031169982, 1073741824, 30

I couldn't find a really good pattern here, although powers of 4 tend to yield better values than odd powers of 2. $2^{21}$ is very strange.

I couldn't find a fast function in SAGE for computing the valuation of a factorial, so I made a Cython file "val.spyx" with the code:

def val(int a, int p):
    cdef int i,r
    i=0
    r=p
    while(a >= r):
        i = i + (a/r)
        r = r*p
    return i

In SAGE, I compiled it with

load ".../val.spyx"

where "..." indicates the directory holding the file (available with the "pwd" UNIX command). Then I wrote three functions (I imagine there are more elegant ways to write these):

def innerloop(a,b,c):
    r=0
    p=2
    while(r==0 and p <= min(b,c)):
        if val(a,p) < val(b,p) + val(c,p):
            r=1
        p=next_prime(p)
    return r

def testvirtue(m,k):
    r=0
    for i in range((m+k+1)/2,m):
        if innerloop(m,i,m-i+k)==0:
            print m,i,m-i+k
            r=1
    return r

def testrange(m,n,k):
    for i in range(m,n):
        if testvirtue(i,k):
            k=k+1
            testvirtue(i,k)
    return k

Anyway, starting with k=3 and running up to 80000 took about 2 hours on my laptop:

10 7 6
36 23 17
36 29 11
56 47 14
100 59 47
162 107 62
162 110 59
256 142 122
256 202 62
256 239 25
256 241 23
261 223 47
261 239 31
416 239 187
1056 620 447
2080 1214 878
2080 1853 239 
3201 1775 1439
4384 2735 1663
32778 18458 14335
32808 18617 14207
32808 23615 9209
65536 34963 30590
65536 39314 26239
65536 39319 26234
65536 39323 26230
65536 39346 26207
65536 39347 26206
65536 52447 13106
65536 39347 26207
19

As you can see from the last entries, the optimal value of $a+b-n$ jumps by 2 to 18 at 65536. I checked a few larger powers of two beyond 80000 - here are the maximal values of $a+b-n$:

4 1
8 1
16 3
32 3
64 4
128 5
256 8
512 8
1024 9
2048 8
4096 11
8192 14
16384 14
32768 14
65536 18
131072 17
262144 20
524288 20
1048576 21
2097152 12
4194304 20
8388608 20
16777216 21

I couldn't find a really good pattern here, although powers of 4 tend to yield better values than odd powers of 2. $2^{21}$ is very strange.

Edit: Following Noam D. Elkies's suggestion, I rewrote my program in C. Also, I found an overflow bug in my valuation routine, as a result of using 32 bit integers, so some of the previous results for $n>65536$ were false. Since the C code is somewhat longer than the SAGE version, I put it here on my web page.

Anyway, starting with k=3 and running up to $2^{23} = 8388608$ took about 3 hours on a 12-core desktop. Here are the results in the form $a, b, n, k$:

3, 5, 6, 2
6, 7, 10, 3
11, 29, 36, 4
14, 47, 56, 5
47, 59, 100, 6
59, 110, 162, 7
23, 241, 256, 8
31, 239, 261, 9
187, 239, 416, 10
447, 620, 1056, 11
239, 1853, 2080, 12
1439, 1775, 3201, 13
1663, 2735, 4384, 14
14335, 18458, 32778, 15
9209, 23615, 32808, 16
13106, 52447, 65536, 17
26207, 39347, 65536, 18
34719, 227444, 262144, 19
109237, 152927, 262144, 20
59039, 465398, 524416, 21
230111, 294839, 524928, 22
496123, 3698204, 4194304, 23
1007871, 3186457, 4194304, 24
983546, 7405087, 8388608, 25
1029947, 7358687, 8388608, 26

I checked a few larger powers of two - here are the maximal values of $a+b-n$:

2, 3, 4, 1
2, 7, 8, 1
5, 14, 16, 3
9, 26, 32, 3
19, 49, 64, 4
17, 116, 128, 5
23, 241, 256, 8
53, 467, 512, 8
314, 719, 1024, 9
482, 1574, 2048, 8
1943, 2164, 4096, 11
1979, 6227, 8192, 14
3317, 13081, 16384, 14
6548, 26234, 32768, 14
26207, 39347, 65536, 18
56375, 74354, 131072, 17
109237, 152927, 262144, 20
58559, 465749, 524288, 20
117350, 931247, 1048576, 21
511613, 1585561, 2097152, 22
1007871, 3186457, 4194304, 24
1029947, 7358687, 8388608, 26
839773, 15937469, 16777216, 26
2479487, 31074973, 33554432, 28
28499711, 38609183, 67108864, 30
13640318, 120577439, 134217728, 29
26335607, 242099879, 268435456, 30
149450463, 387420479, 536870912, 30
42571871, 1031169982, 1073741824, 30
Source Link
S. Carnahan
  • 45.7k
  • 6
  • 114
  • 220

First, I'd like to revisit Will Sawin's upper bound, but I make no promises about off-by-one errors (which I think I made in comments elsewhere on this page). The product of any sequence of $x$ consecutive integers has $p$-valuation at least $\lfloor \frac{x}{p-1}\rfloor - \lfloor \log_p(x+1) \rfloor$. The $p$-valuation of $\binom{n}{a}$ is the number of carries when adding $a$ to $n-a$ in base $p$, so this is bounded above by $\lfloor \log_p n \rfloor$. In other words, the product of the $x = b-(n-a)$ integers from $n-a+1$ to $b$ must satisfy $\lfloor \frac{x}{p-1}\rfloor - \lfloor \log_p(x+1) \rfloor \leq \lfloor \log_p n \rfloor$. Pushing some terms around yields the bound $$x \leq (p-1)\lfloor log_p(n) \rfloor +(p-1) \lfloor log_p log_p n \rfloor + 2p - 2.$$ If we only worry about making $\frac{n!}{a!b!}$ into a 2-adic integer instead of an ordinary integer, then this bound is sharp, since the case $n=2^k, a=2^k-1, b = 2^y-1$ saturates it when $k = 2^y-y-1$.

When $n$ is large, $(p-1) \lfloor \log_p(n) \rfloor > \lfloor \log_2(n) \rfloor$ for odd $p$, so this suggests that it is good to check 2-valuations when eliminating candidate triples. By request, here is some computer code.

I couldn't find a fast function in SAGE for computing the valuation of a factorial, so I made a Cython file "val.spyx" with the code:

def val(int a, int p):
    cdef int i,r
    i=0
    r=p
    while(a >= r):
        i = i + (a/r)
        r = r*p
    return i

In SAGE, I compiled it with

load ".../val.spyx"

where "..." indicates the directory holding the file (available with the "pwd" UNIX command). Then I wrote three functions (I imagine there are more elegant ways to write these):

def innerloop(a,b,c):
    r=0
    p=2
    while(r==0 and p <= min(b,c)):
        if val(a,p) < val(b,p) + val(c,p):
            r=1
        p=next_prime(p)
    return r

def testvirtue(m,k):
    r=0
    for i in range((m+k+1)/2,m):
        if innerloop(m,i,m-i+k)==0:
            print m,i,m-i+k
            r=1
    return r

def testrange(m,n,k):
    for i in range(m,n):
        if testvirtue(i,k):
            k=k+1
            testvirtue(i,k)
    return k

Anyway, starting with k=3 and running up to 80000 took about 2 hours on my laptop:

10 7 6
36 23 17
36 29 11
56 47 14
100 59 47
162 107 62
162 110 59
256 142 122
256 202 62
256 239 25
256 241 23
261 223 47
261 239 31
416 239 187
1056 620 447
2080 1214 878
2080 1853 239 
3201 1775 1439
4384 2735 1663
32778 18458 14335
32808 18617 14207
32808 23615 9209
65536 34963 30590
65536 39314 26239
65536 39319 26234
65536 39323 26230
65536 39346 26207
65536 39347 26206
65536 52447 13106
65536 39347 26207
19

As you can see from the last entries, the optimal value of $a+b-n$ jumps by 2 to 18 at 65536. I checked a few larger powers of two beyond 80000 - here are the maximal values of $a+b-n$:

4 1
8 1
16 3
32 3
64 4
128 5
256 8
512 8
1024 9
2048 8
4096 11
8192 14
16384 14
32768 14
65536 18
131072 17
262144 20
524288 20
1048576 21
2097152 12
4194304 20
8388608 20
16777216 21

I couldn't find a really good pattern here, although powers of 4 tend to yield better values than odd powers of 2. $2^{21}$ is very strange.