########################################################################## # Copyright (C) 2006 Jaap Spies, jaapspies@gmail.com # Copyright (C) 2006 William Stein, wstein@gmail.com # # Distributed under the terms of the GNU General Public License (GPL): # # http://www.gnu.org/licenses/ ############################################################### def A111776(n): r""" This function returns the $n$-th number of sequence A111776 $n$ is the sum of at most $a(n)$ consecutive positive integers. Suppose $n$ is to be written as sum of $k$ consecutive integers starting with $m$, then $2n = k(2m + k - 1)$. Only one of the factors is odd. For each odd divisor $d$ of $n$ there is a unique corresponding $k = min(d,2n/d)$. $a(n)$ is the largest among those $k$ . See: http://www.jaapspies.nl/mathfiles/problem2005-2C.pdf INPUT: n -- non negative integer OUTPUT: integer -- function value EXAMPLES: sage: A111776(15) 5 sage: A111776(1000) 25 sage: A111776(51) 6 sage: A111776(23) 2 sage: A111776(1) 1 AUTHOR: - Jaap Spies (2006-12-08) """ if n == 1 or n == 0: return 1 m = 0 for d in [i for i in divisors(n) if i%2]: # d is odd divisor k = min(d, 2*n/d) if k > m: m = k return m def A111776_list(N): return [A111776(i) for i in range(0,N+1)]