Solving the Equation 1/a + 1/b = p / 10^n
For each n from 1 to 9, count the number of solutions (a, b, p) where a, b, p are positive integers with a <= b, satisfying: (1)/(a) + (1)/(b) = (p)/(10^n) Sum the counts over n = 1, 2,..., 9.
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Consider the diophantine equation \(\frac 1 a + \frac 1 b = \frac p {10^n}\) with \(a, b, p, n\) positive integers and \(a \le b\).
For \(n=1\) this equation has \(20\) solutions that are listed below: \[ \begin {array}{ccccc} \frac {1}{1} + \frac {1}{1} = \frac {20}{10} & \frac {1}{1} + \frac {1}{2} = \frac {15}{10} & \frac {1}{1} + \frac {1}{5} = \frac {12}{10} & \frac {1}{1} + \frac {1}{10} = \frac {11}{10} & \frac {1}{2} + \frac {1}{2} = \frac {10}{10} \\[12pt] \frac {1}{2} + \frac {1}{5} = \frac {7}{10} & \frac {1}{2} + \frac {1}{10} = \frac {6}{10} & \frac {1}{3} + \frac {1}{6} = \frac {5}{10} & \frac {1}{3} + \frac {1}{15} = \frac {4}{10} & \frac {1}{4} + \frac {1}{4} = \frac {5}{10} \\[12pt] \frac {1}{4} + \frac {1}{20} = \frac {3}{10} & \frac {1}{5} + \frac {1}{5} = \frac {4}{10} & \frac {1}{5} + \frac {1}{10} = \frac {3}{10} & \frac {1}{6} + \frac {1}{30} = \frac {2}{10} & \frac {1}{10} + \frac {1}{10} = \frac {2}{10} \\[12pt] \frac {1}{11} + \frac {1}{110} = \frac {1}{10} & \frac {1}{12} + \frac {1}{60} = \frac {1}{10} & \frac {1}{14} + \frac {1}{35} = \frac {1}{10} & \frac {1}{15} + \frac {1}{30} = \frac {1}{10} & \frac {1}{20} + \frac {1}{20} = \frac {1}{10} \end {array} \] How many solutions has this equation for \(1 \le n \le 9\)?
Problem 157: Solving the Equation 1/a + 1/b = p / 10^n
Mathematical Analysis
Key Transformation
Let . From :
Rearranging and completing the product:
Multiply by and add :
Enumeration via Divisors
Let and with .
Claim: Both and must be positive.
Proof: Since , we need and . If and , then and , giving , contradicting . If one is positive and one negative, . So both are positive.
For each divisor of with (ensuring , which gives ):
- Set .
- Compute .
- Each divisor of yields a valid solution: , .
- Since requires (already ensured), and are positive integers when , the contribution from this divisor pair is , the number of positive divisors of .
Proof of Correctness
Given a divisor pair with , and any positive divisor of :
- and are positive integers.
- , which expands to .
- Hence with .
- Conversely, every solution arises this way.
Why divisors of suffice
. Its divisors are exactly the numbers with . The number of divisors is .
Counting formula
Per- breakdown
| Count | |
|---|---|
| 1 | 20 |
| 2 | 102 |
| 3 | 356 |
| 4 | 958 |
| 5 | 2192 |
| 6 | 4456 |
| 7 | 8260 |
| 8 | 14088 |
| 9 | 23058 |
Complexity
The number of divisors of is . For each divisor pair, we compute a GCD () and count divisors (). Total work is negligible.
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;
// Count number of positive divisors of n
int count_divisors(ll n) {
if (n <= 0) return 0;
int count = 0;
for (ll d = 1; d * d <= n; d++) {
if (n % d == 0) {
count++;
if (d != n / d) count++;
}
}
return count;
}
// Get all divisors of 10^(2n) = 2^(2n) * 5^(2n)
vector<ll> get_divisors(int n2) {
vector<ll> divs;
for (int a = 0; a <= n2; a++) {
for (int b = 0; b <= n2; b++) {
ll d = 1;
for (int i = 0; i < a; i++) d *= 2;
for (int i = 0; i < b; i++) d *= 5;
divs.push_back(d);
}
}
sort(divs.begin(), divs.end());
return divs;
}
int main() {
ll total = 0;
for (int n = 1; n <= 9; n++) {
ll N = 1;
for (int i = 0; i < n; i++) N *= 10;
ll N2 = N * N;
vector<ll> divs = get_divisors(2 * n);
for (ll u : divs) {
if (u > N) continue; // u <= N ensures a <= b
ll v = N2 / u;
ll g = __gcd(N + u, N + v);
total += count_divisors(g);
}
}
cout << total << endl;
return 0;
}
from math import gcd
def count_divisors(n):
"""Count the number of positive divisors of n."""
if n <= 0:
return 0
count = 0
d = 1
while d * d <= n:
if n % d == 0:
count += 1
if d != n // d:
count += 1
d += 1
return count
def get_divisors(n2):
"""Get all divisors of 10^n2 = 2^n2 * 5^n2."""
divs = []
for a in range(n2 + 1):
for b in range(n2 + 1):
divs.append(2**a * 5**b)
return sorted(divs)
total = 0
for n in range(1, 10):
N = 10**n
N2 = N * N
divs = get_divisors(2 * n)
subtotal = 0
for u in divs:
if u > N:
continue # ensures a <= b
v = N2 // u
g = gcd(N + u, N + v)
subtotal += count_divisors(g)
total += subtotal
print(total)