Homepage Solution manuals Ivan Niven An Introduction to the Theory of Numbers Exercise 4.5.12* (If $1 \leq k \leq (n^2 + n)/2$, there is a subset of the set $[\![1, n]\!]$ whose sum is $k$)

Exercise 4.5.12* (If $1 \leq k \leq (n^2 + n)/2$, there is a subset of the set $[\![1, n]\!]$ whose sum is $k$)

Let n and k be positive integers such that 1 k ( n 2 + n ) 2 . Prove that there is a subset of the set { 1 , 2 , 3 , , n } whose sum is k .

Answers

Proof. We prove this property by induction on n . We write T n = n ( n + 1 ) 2 = 1 + 2 + + n the n -th triangular number. Consider the proposition

𝒫 ( n ) k [ [ 1 , T n ] ] , I [ [ 1 , n ] ] , k = i I i .

  • If n = 1 , the only integer k such that k [ [ 1 , T 1 ] is k = 1 , and k = 1 = i { 1 } i , where I = { 1 } [ [ 1 , n ] ] = { 1 } , so 𝒫 ( 1 ) is true.
  • Suppose now that 𝒫 ( n 1 ) is true for some n 2 . Let k be any element of [ [ 1 , T n ] ] .

    • If k T n 1 , then the induction hypothesis 𝒫 ( n 1 ) shows that n = i I i , where I [ [ 1 , n 1 ] ] [ [ 1 , n ] ] .
    • If k = T n , then k = i [ [ 1 , n ] ] i .
    • If T n 1 < k < T n , then k = T n h for some h such that 1 h < T n T n 1 = n . Therefore

      k = T n h = ( i [ [ 1 , n ] ] i ) h = i [ [ 1 , n ] ] { h } i .

      So k = i J i , where J = [ [ 1 , n ] ] { h } [ [ 1 , n ] ] .

  • In all cases, k = i I i for some I [ [ 1 , n ] ] , so 𝒫 ( n ) is true, and the induction is done.

This shows that for every positive integer n , every k [ [ 1 , ( n 2 + n ) 2 ] ] is a sum k = i I i for some I [ [ 1 , n ] ] . □

Note: Following this algorithm, we give a function in sagemath which return the list of elements of I [ [ 1 , n ] ] , where n is the least integer such that k n ( n + 1 ) 2 .

def find_n(k):
    """find n such that T_(n-1)< k <= T_n"""
    return ceil(sqrt(2 * k + 0.25) - 0.5)

def representation(k):
    """return a list of elements i <= n whose sum is k,
    where n is the least integer such that k <= T_n"""
    n = find_n(k)
    Tn = (n * (n + 1))// 2
    l = list(range(1, n + 1))
    h = Tn - k
    if h >0: l.remove(h)
    return l

representation(18)
            [1, 2, 4, 5, 6]

User profile picture
2025-03-31 10:37
Comments