Exploring Pascal's Triangle
How many entries C(200000, i,j,k) = (200000!)/(i! j! k!) with i + j + k = 200000 are divisible by 10^12?
Problem Statement
This archive keeps the full statement, math, and original media on the page.

Problem 154: Exploring Pascal’s Triangle
Mathematical Foundation
Theorem 1 (Legendre’s Formula). For a prime and non-negative integer :
where denotes the -adic valuation.
Proof. Each integer contributes to . We have . Swapping summation: .
Theorem 2 (Trinomial Valuation). For the trinomial coefficient with :
This equals the total number of carries when adding , , in base (Kummer’s theorem generalization).
Proof. Direct from and the additive property of .
Lemma 1 (Divisibility Condition). if and only if and .
Proof. Since and , the divisibility holds iff both prime-power conditions hold.
Lemma 2 (Symmetry Reduction). The number of ordered triples with satisfying the divisibility condition can be computed by iterating over and applying symmetry multipliers:
- if (all distinct),
- if exactly two of are equal,
- if .
Proof. The trinomial coefficient is symmetric in . The multinomial coefficient for the number of distinct permutations of gives the multiplier.
Editorial
the trinomial coefficient IS divisible by 10^12. v_p(C(n; i,j,k)) = v_p(n!) - v_p(i!) - v_p(j!) - v_p(k!) We need v_2 >= 12 AND v_5 >= 12. Note: This Python solution is slow for N=200000 (O(N^2) iterations). For the actual answer, use the C++ version. This serves as a reference. We precompute p-adic valuations of factorials. We then precompute target valuations. Finally, check v_2 condition.
Pseudocode
Precompute p-adic valuations of factorials
Precompute target valuations
Check v_2 condition
Check v_5 condition
Count with symmetry
else
Complexity Analysis
- Time: for precomputation of and . The main loop iterates over triples, each in . Total: where , giving approximately operations. (In practice, the inner loop often terminates early.)
- Space: for the precomputed valuation arrays.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
/*
* Problem 154: Count triples (i,j,k) with i+j+k=200000 where
* the trinomial coefficient IS divisible by 10^12.
*
* v_p(binom(n; i,j,k)) = v_p(n!) - v_p(i!) - v_p(j!) - v_p(k!)
* Need v_2 >= 12 AND v_5 >= 12.
*/
int main() {
const int N = 200000;
const int TARGET = 12;
// Precompute v_p(m!) for p = 2 and p = 5
vector<int> v2(N + 1), v5(N + 1);
v2[0] = v5[0] = 0;
for (int m = 1; m <= N; m++) {
int x = m, c2 = 0, c5 = 0;
while (x % 2 == 0) { c2++; x /= 2; }
x = m;
while (x % 5 == 0) { c5++; x /= 5; }
v2[m] = v2[m - 1] + c2;
v5[m] = v5[m - 1] + c5;
}
int V2N = v2[N];
int V5N = v5[N];
long long count = 0;
// Iterate i <= j <= k, i+j+k = N
// So i <= N/3, j >= i, k = N-i-j >= j => j <= (N-i)/2
for (int i = 0; i <= N / 3; i++) {
// For v_p: need V_pN - v_p[i] - v_p[j] - v_p[N-i-j] < TARGET
int r2i = V2N - v2[i]; // v2 of binom without j,k parts
int r5i = V5N - v5[i];
for (int j = i; j <= (N - i) / 2; j++) {
int k = N - i - j;
int val2 = r2i - v2[j] - v2[k];
int val5 = r5i - v5[j] - v5[k];
if (val2 >= TARGET && val5 >= TARGET) {
// Count with multiplicity
if (i == j && j == k) count += 1;
else if (i == j || j == k) count += 3;
else count += 6;
}
}
}
printf("%lld\n", count);
return 0;
}
"""
Problem 154: Count triples (i,j,k) with i+j+k=200000 where
the trinomial coefficient IS divisible by 10^12.
v_p(C(n; i,j,k)) = v_p(n!) - v_p(i!) - v_p(j!) - v_p(k!)
We need v_2 >= 12 AND v_5 >= 12.
Note: This Python solution is slow for N=200000 (O(N^2) iterations).
For the actual answer, use the C++ version. This serves as a reference.
"""
def solve():
N = 200000
TARGET = 12
# Precompute v_p(m!) for p=2 and p=5
v2 = [0] * (N + 1)
v5 = [0] * (N + 1)
for m in range(1, N + 1):
x = m
c2 = 0
while x % 2 == 0:
c2 += 1
x //= 2
x = m
c5 = 0
while x % 5 == 0:
c5 += 1
x //= 5
v2[m] = v2[m - 1] + c2
v5[m] = v5[m - 1] + c5
V2N = v2[N]
V5N = v5[N]
count = 0
for i in range(N // 3 + 1):
r2i = V2N - v2[i]
r5i = V5N - v5[i]
for j in range(i, (N - i) // 2 + 1):
k = N - i - j
val2 = r2i - v2[j] - v2[k]
val5 = r5i - v5[j] - v5[k]
if val2 >= TARGET and val5 >= TARGET:
if i == j == k:
count += 1
elif i == j or j == k:
count += 3
else:
count += 6
print(count)
solve()