Squarefree Binomial Coefficients
Find the sum of all distinct squarefree numbers in the first 51 rows (rows 0 through 50) of Pascal's triangle.
Problem Statement
This archive keeps the full statement, math, and original media on the page.
The binomial coefficients \(\displaystyle \binom n k\) can be arranged in triangular form, Pascal’s triangle, like this:
\[ \begin {array}{cccccccccccccccc} &&&&&&& 1 &&&&&&& \\ &&&&&& 1 && 1 &&&&&& \\ &&&&& 1 && 2 && 1 &&&&& \\ &&&& 1 && 3 && 3 && 1 &&&& \\ &&& 1 && 4 && 6 && 4 && 1 &&& \\ && 1 && 5 && 10 && 10 && 5 && 1 && \\ & 1 && 6 && 15 && 20 && 15 && 6 && 1 & \\ 1 && 7 && 21 && 35 && 35 && 21 && 7 && 1 \\ &&&&&&& \ldots &&&&&&& \\ \end {array} \]
It can be seen that the first eight rows of Pascal’s triangle contain twelve distinct numbers: \(1\), \(2\), \(3\), \(4\), \(5\), \(6\), \(7\), \(10\), \(15\), \(20\), \(21\) and \(35\).
A positive integer \(n\) is called squarefree if no square of a prime divides \(n\). Of the twelve distinct numbers in the first eight rows of Pascal’s triangle, all except \(4\) and \(20\) are squarefree. The sum of the distinct squarefree numbers in the first eight rows is 105.
Find the sum of the distinct squarefree numbers in the first 51 rows of Pascal’s triangle.
Problem 203: Squarefree Binomial Coefficients
Mathematical Foundation
Theorem (Kummer, 1852). For a prime and non-negative integers , the -adic valuation equals the number of carries when adding and in base .
Proof. By Legendre’s formula, . Therefore:
Each term equals 0 or 1, and it equals 1 precisely when there is a carry out of position in the base- addition of and . This is a standard result; see Granville (1997) for a detailed proof.
Lemma (Bounded Valuation for Large Primes). For and any prime , every binomial coefficient satisfies .
Proof. Since and , both and have at most 2 digits in base . Adding two numbers with at most 2 digits produces at most 1 carry (from the units digit to the ‘s digit). By Kummer’s theorem, .
Theorem (Squarefreeness Criterion). A binomial coefficient with is squarefree if and only if is not divisible by any of .
Proof. A positive integer is squarefree iff for every prime . By the Lemma, automatically holds for all primes . Thus squarefreeness fails only if for some prime , which is equivalent to for .
Editorial
By Kummer’s theorem, for n <= 50, primes >= 11 can appear at most once in any binomial coefficient. So squarefreeness reduces to checking divisibility by 4, 9, 25, and 49. We return sum(S).
Pseudocode
Input: N = 50
Output: sum of distinct squarefree values in rows 0..N of Pascal's triangle
S = empty set
For n = 0 to N:
Return sum(S)
Complexity Analysis
- Time: to generate all binomial coefficients. Each squarefreeness test is (four divisibility checks). Set insertion is amortized, and .
- Space: for the set of distinct squarefree values.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main(){
// Find sum of distinct squarefree binomial coefficients in rows 0..50.
// By Kummer's theorem, for n<=50, only primes 2,3,5,7 can appear with
// exponent >= 2. So check divisibility by 4, 9, 25, 49.
const int N = 50;
set<long long> vals;
// Generate Pascal's triangle
vector<vector<long long>> C(N+1);
for(int n = 0; n <= N; n++){
C[n].resize(n+1);
C[n][0] = C[n][n] = 1;
for(int k = 1; k < n; k++){
C[n][k] = C[n-1][k-1] + C[n-1][k];
}
for(int k = 0; k <= n; k++){
vals.insert(C[n][k]);
}
}
long long ans = 0;
for(long long v : vals){
if(v % 4 != 0 && v % 9 != 0 && v % 25 != 0 && v % 49 != 0){
ans += v;
}
}
cout << ans << endl;
return 0;
}
"""
Problem 203: Squarefree Binomial Coefficients
Find the sum of all distinct squarefree numbers in the first 51 rows
(rows 0 through 50) of Pascal's triangle.
By Kummer's theorem, for n <= 50, primes >= 11 can appear at most once
in any binomial coefficient. So squarefreeness reduces to checking
divisibility by 4, 9, 25, and 49.
"""
def solve():
N = 50
vals = set()
# Build Pascal's triangle
row = [1]
vals.add(1)
for n in range(1, N + 1):
new_row = [1]
for k in range(1, n):
new_row.append(row[k-1] + row[k])
new_row.append(1)
row = new_row
vals.update(row)
# Check squarefreeness (only need to test p^2 for p in {2,3,5,7})
squares = [4, 9, 25, 49]
ans = sum(v for v in vals if all(v % sq != 0 for sq in squares))
print(ans)
if __name__ == "__main__":
solve()