#P5253. Counting Distinct Solutions of a Diophantine Equation
Counting Distinct Solutions of a Diophantine Equation
Counting Distinct Solutions of a Diophantine Equation
Consider the Diophantine equation:
$$\frac{1}{x} + \frac{1}{y} = \frac{1}{n}, \quad (x,y,n \in \mathbb{N}^+)$$
For a given positive integer \(n\), your task is to count the number of essentially different solutions \( (x, y) \) (with \(x \le y\)) that satisfy the equation. For example, when \(n = 4\), there are three distinct solutions:
- $$\frac{1}{5} + \frac{1}{20} = \frac{1}{4}$$
- $$\frac{1}{6} + \frac{1}{12} = \frac{1}{4}$$
- $$\frac{1}{8} + \frac{1}{8} = \frac{1}{4}$$
By substituting \(x = n + a\) and \(y = n + b\), the equation reduces to \(a \times b = n^2\) (with \(a, b \in \mathbb{N}^+\)). Thus, the number of distinct solutions \( (x, y) \) with \(x \le y\) is equal to the number of pairs \((a, b)\) with \(a \times b = n^2\) and \(a \le b\). It can be shown that the answer is given by: $$\text{Answer} = \frac{d(n^2) + 1}{2},$$ where \(d(n^2)\) is the number of positive divisors of \(n^2\).
inputFormat
The input contains a single positive integer \(n\) on a single line.
outputFormat
Output a single integer representing the number of essentially different solutions \((x, y)\) (with \(x \le y\)) that satisfy the equation.
sample
4
3