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 and be positive integers such that . Prove that there is a subset of the set whose sum is .
Answers
Proof. We prove this property by induction on . We write the -th triangular number. Consider the proposition
- If , the only integer such that is , and , where , so is true.
-
Suppose now that is true for some . Let be any element of .
- If , then the induction hypothesis shows that , where .
- If , then .
-
If , then for some such that . Therefore
So , where .
- In all cases, for some , so is true, and the induction is done.
This shows that for every positive integer , every is a sum for some . □
Note: Following this algorithm, we give a function in sagemath which return the list of elements of , where is the least integer such that .
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]