Divisibility Streaks
For every positive integer n, define streak(n) = k as the smallest positive integer k such that n + k is not divisible by k + 1. Examples: streak(13) = 4 because 2 | 14, 3 | 15, 4 | 16, but 5 nmid...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
For every positive number \(n\) we define the function \(\mathop {streak}(n)=k\) as the smallest positive integer \(k\) such that \(n+k\) is not divisible by \(k+1\).
E.g:
\(13\) is divisible by \(1\)
\(14\) is divisible by \(2\)
\(15\) is divisible by \(3\)
\(16\) is divisible by \(4\)
\(17\) is NOT divisible by \(5\)
So \(\mathop {streak}(13) = 4\).
Similarly:
\(120\) is divisible by \(1\)
\(121\) is NOT divisible by \(2\)
So \(\mathop {streak}(120) = 1\).
Define \(P(s, N)\) to be the number of integers \(n\), \(1 < n N\), for which \(\mathop {streak}(n) = s\).
So \(P(3, 14) = 1\) and \(P(6, 10^6) = 14286\).
Find the sum, as \(i\) ranges from \(1\) to \(31\), of \(P(i, 4^i)\).
Problem 601: Divisibility Streaks
Mathematical Foundation
Definition. Let for , and .
Theorem 1. For all positive integers and , if and only if , where .
Proof. The condition means for all . Since , we have if and only if , i.e., .
The system of congruences for is equivalent to . Reindexing, requires for , i.e., for , which is .
However, adopting the convention complicates notation. Instead, note that means for , equivalently .
Let us define . Then .
Lemma 1. The number of integers with satisfying is .
Proof. We need to count integers with . Substituting , we count with . The number of positive multiples of up to is .
Theorem 2 (Counting Formula). Let . Then
Proof. means and . By Theorem 1, this is and . By Lemma 1, the count of with is , and the count with is . By inclusion, .
Remark. By the Prime Number Theorem, (Chebyshev’s theorem gives ), so grows roughly as . For large , , making the second floor term zero.
Editorial
We enumerate the admissible parameter range, discard candidates that violate the derived bounds or arithmetic constraints, and update the final set or total whenever a candidate passes the acceptance test.
Pseudocode
M[1] = 1
For k from 2 to 33:
M[k] = lcm(M[k-1], k+1) // M[s] = lcm(2, 3, ..., s+1)
total = 0
For i from 1 to 31:
N = 4^i
term = floor((N - 2) / M[i]) - floor((N - 2) / M[i+1])
total = total + term
Return total
Complexity Analysis
- Time: where is the cost of big-integer division. Since and have digits, each division is with schoolbook arithmetic, giving (constant with respect to any scaling parameter).
- Space: where is the maximum digit count of , which is bounded by a constant.
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() {
// streak(n) = k: smallest k s.t. n+k NOT div by k+1
// streak(n) >= s: n ≡ 1 (mod lcm(2,...,s))
// P(s,N) = floor((N-2)/lcm(2,...,s)) - floor((N-2)/lcm(2,...,s+1))
// Answer = sum_{i=1}^{31} P(i, 4^i)
typedef __int128 lll;
auto my_gcd = [](lll a, lll b) -> lll {
while (b) { a %= b; swap(a, b); }
return a;
};
// L[k] = lcm(2, 3, ..., k)
vector<lll> L(34, 1);
lll cur = 1;
for (int k = 2; k <= 33; k++) {
cur = cur / my_gcd(cur, (lll)k) * k;
L[k] = cur;
}
lll ans = 0;
for (int i = 1; i <= 31; i++) {
lll N = 1;
for (int j = 0; j < i; j++) N *= 4;
lll Nm2 = N - 2;
lll c1;
if (i == 1) {
c1 = Nm2;
} else {
c1 = (L[i] <= Nm2) ? Nm2 / L[i] : 0;
}
lll c2 = (L[i+1] <= Nm2) ? Nm2 / L[i+1] : 0;
ans += c1 - c2;
}
// Print __int128
long long result = (long long)ans;
cout << result << endl;
return 0;
}
from math import gcd
def solve():
# streak(n) = k: smallest k such that n+k NOT divisible by k+1
# streak(n) >= s: n+j divisible by j+1 for j=1..s-1
# i.e., n ≡ 1 (mod lcm(2,3,...,s))
# streak(n) = s: streak >= s but not >= s+1
# P(s, N) = floor((N-2)/lcm(2,...,s)) - floor((N-2)/lcm(2,...,s+1))
# Special case s=1: P(1,N) = (N-2) - floor((N-2)/2)
def lcm(a, b):
return a // gcd(a, b) * b
# L[k] = lcm(2, 3, ..., k)
L = {1: 1}
cur = 1
for k in range(2, 34):
cur = lcm(cur, k)
L[k] = cur
def P(s, N):
Nm2 = N - 2
if s == 1:
c1 = Nm2
else:
Ls = L[s]
c1 = Nm2 // Ls if Ls <= Nm2 else 0
Ls1 = L[s + 1]
c2 = Nm2 // Ls1 if Ls1 <= Nm2 else 0
return c1 - c2
ans = sum(P(i, 4**i) for i in range(1, 32))
print(ans)
solve()