########################################################################## # 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 A111774(n): r""" This function returns the $n$-th number of Sloane's sequence A111774 """ a = A111774_list(150) return a[n-1] def A111774_list(n): return [i for i in range(1, n+1) if is_number_of_the_third_kind(i)] def is_number_of_the_third_kind(n): r"""" This function returns True iff $n$ is a number of the third kind. A number of the third kind can be written as a sum of at least three consecutive positive integers. Odd primes can only be written as a sum of two consecutive integers. Powers of 2 do not have a representation as a sum of $k$ consecutive integers (other than the trivial $n = n$ for $k = 1$). See: http://www.jaapspies.nl/mathfiles/problem2005-2C.pdf INPUT: n -- positive integer OUTPUT: True -- if n is not prime and not a power of 2 False -- EXAMPLES: sage: is_number_of_the_third_kind(6) True sage: is_number_of_the_third_kind(100) True sage: is_number_of_the_third_kind(16) False sage: is_number_of_the_third_kind(97) False AUTHOR: - Jaap Spies (2006-12-09) """ if (not is_prime(n)) and (not is_power_of_two(n)): return True else: return False def is_power_of_two(n): r"""" This function returns True iff $n$ is a power of 2 INPUT: n -- integer OUTPUT: True -- if n is a power of 2 False -- if not EXAMPLES: sage: is_power_of_two(1024) True sage: is_power_of_two(1) True sage: is_power_of_two(24) False sage: is_power_of_two(0) False sage: is_power_of_two(-4) False AUTHOR: - Jaap Spies (2006-12-09) """ # modification of is2pow(n) from the Programming Guide while n > 0 and n%2 == 0: n = n >> 1 return n == 1