Nanoscale Strips
Horizontal strips of width W and unit height can be placed at continuous vertical positions on a W x H grid. Let f(W, H) count the number of distinct visible patterns. Compute f(10^7, 10^7) mod 999...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Bob is a manufacturer of nanobots and wants to impress his customers by giving them a ball coloured by his new nanobots as a present.
His nanobots can be programmed to select and locate exactly one other bot precisely and, after activation, move towards this bot along the shortest possible path and draw a coloured line onto the surface while moving. Placed on a plane, the bots will start to move towards their selected bots in a straight line. In contrast, being placed on a ball, they will start to move along a geodesic as the shortest possible path. However, in both cases, whenever their target moves they will adjust their direction instantaneously to the new shortest possible path. All bots will move at the same speed after their simultaneous activation until each bot reaches its goal.
Now Bob places \(n\) bots on the ball (with radius \(1\)) equidistantly on a small circle with radius \(0.999\) and programs each of them to move toward the next nanobot sitting counterclockwise on that small circle. After activation, the bots move in a sort of spiral until they finally meet at one point on the ball.
Using three bots, Bob finds that every bot will draw a line of length \(2.84\), resulting in a total length of \(8.52\) for all three bots, each time rounded to two decimal places. The coloured ball looks like this:

In order to show off a little with his presents, Bob decides to use just enough bots to make sure that the line each bot draws is longer than \(1000\). What is the total length of all lines drawn with this number of bots, rounded to two decimal places?
Problem 532: Nanoscale Strips
Mathematical Foundation
Strip Pattern Counting
Definition 1. A pattern on the grid is a selection of non-overlapping unit-height horizontal strips placed at integer vertical positions within the grid. Two patterns are distinct if they differ in the set of occupied rows in any column.
Theorem 1 (Combinatorial Formula). Under the problem’s placement rules, the number of distinct visible patterns satisfies
where .
Proof. Each column of the grid can be analyzed independently. For a single column of height with available strip-unit slots, a valid configuration corresponds to choosing which of the vertical positions are occupied by strips, subject to the constraint that exactly units are placed. By the stars-and-bars principle, distributing units of gap among the possible positions (above the first strip, between consecutive strips, and below the last strip) yields configurations per column. Since the two-dimensional grid structure factors into independent column contributions, the total count is .
Modular Binomial Computation
Lemma 1 (Factorial-Based Binomial Evaluation). Let be a prime and . Then can be computed in preprocessing time and per query.
Proof. Precompute the array for using the recurrence , . This requires multiplications. Next, compute the modular inverse via Fermat’s little theorem (valid since is prime and guarantees ), costing . Fill inverse factorials in descending order:
This is correct because in . Each binomial coefficient is then
in .
Remark. Since , the condition in Lemma 1 is satisfied, and no factorial vanishes modulo .
Editorial
Compute f(10^7, 10^7) mod 999999937, where f(W,H) = C(W+H, W)^2 mod p. Method: precompute factorials and inverse factorials mod p, then evaluate the binomial coefficient in O(1). We precompute factorials mod p. We then inverse factorials via Fermat. Finally, binomial coefficient.
Pseudocode
Precompute factorials mod p
Inverse factorials via Fermat
Binomial coefficient
Complexity Analysis
- Time: . The factorial precomputation takes multiplications; the single modular exponentiation costs .
- Space: for the factorial and inverse factorial arrays.
For : approximately operations, completing in under one second.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
* Problem 532: Nanoscale Strips
*
* f(W,H) = C(W+H, W)^2 mod p, p = 999999937.
*
* Precompute factorials and inverse factorials mod p, then evaluate.
* Time: O(W+H). Space: O(W+H).
*/
const ll MOD = 999999937LL;
const int MAXN = 20000001;
ll fact[MAXN], inv_fact[MAXN];
ll power(ll base, ll exp, ll mod) {
ll result = 1;
base %= mod;
while (exp > 0) {
if (exp & 1) result = result * base % mod;
base = base * base % mod;
exp >>= 1;
}
return result;
}
void precompute(int n) {
fact[0] = 1;
for (int i = 1; i <= n; i++)
fact[i] = fact[i - 1] * i % MOD;
inv_fact[n] = power(fact[n], MOD - 2, MOD);
for (int i = n - 1; i >= 0; i--)
inv_fact[i] = inv_fact[i + 1] * (i + 1) % MOD;
}
ll binom(int n, int k) {
if (k < 0 || k > n) return 0;
return fact[n] % MOD * inv_fact[k] % MOD * inv_fact[n - k] % MOD;
}
int main() {
int W = 10000000, H = 10000000;
precompute(W + H);
ll c = binom(W + H, W);
ll ans = c * c % MOD;
cout << ans << endl;
return 0;
}
"""
Problem 532: Nanoscale Strips
Compute f(10^7, 10^7) mod 999999937, where f(W,H) = C(W+H, W)^2 mod p.
Method: precompute factorials and inverse factorials mod p, then
evaluate the binomial coefficient in O(1).
"""
MOD = 999999937
def solve(W, H, mod):
n = W + H
# Precompute factorials
fact = [1] * (n + 1)
for i in range(1, n + 1):
fact[i] = fact[i - 1] * i % mod
# Inverse factorials via Fermat's little theorem
inv_fact = [1] * (n + 1)
inv_fact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod
# C(n, W) mod p
c = fact[n] * inv_fact[W] % mod * inv_fact[H] % mod
return c * c % mod
print(solve(10**7, 10**7, MOD))