Count Integer Pairs Satisfying 1/x + 1/y = 1/N!

Quick Overview

Count the ordered pairs of positive integers x and y that satisfy 1/x + 1/y = 1/n! for n up to one million, with the count returned modulo 10^9 + 7. It tests rearranging a Diophantine equation, reasoning about the prime factorization of a factorial, and keeping the work far below the size of n!.

Count Integer Pairs Satisfying 1/x + 1/y = 1/N!

Company: Point72

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

Given a positive integer `n`, count the pairs of positive integers `(x, y)` that satisfy $$\frac{1}{x} + \frac{1}{y} = \frac{1}{n!}$$ The count grows very fast with `n`, so return it modulo ${10^9 + 7}$. ### Function Signature ```python def count_pairs(n: int) -> int: ``` ### Rules - Count ordered pairs: when `x != y`, `(x, y)` and `(y, x)` are two different pairs. - Both `x` and `y` must be positive integers. - Return the count modulo `1000000007`. ### Constraints - `1 <= n <= 10^6` ### Examples ```text Input: n = 1 Output: 1 ``` Here `n! = 1`, and the only solution is (2, 2), since 1/2 + 1/2 = 1. ```text Input: n = 2 Output: 3 ``` Here `n! = 2`, and the solutions are (3, 6), (4, 4) and (6, 3). For instance, 1/3 + 1/6 = 1/2. ```text Input: n = 3 Output: 9 ``` Here `n! = 6`. The solutions are (7, 42), (8, 24), (9, 18), (10, 15), (12, 12) and the four reversals (15, 10), (18, 9), (24, 8) and (42, 7).

Overview: Count the ordered pairs of positive integers x and y that satisfy 1/x + 1/y = 1/n! for n up to one million, with the count returned modulo 10^9 + 7. It tests rearranging a Diophantine equation, reasoning about the prime factorization of a factorial, and keeping the work far below the size of n!.

Point72 logo
Point72
Nov 25, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Given a positive integer n, count the pairs of positive integers (x, y) that satisfy

1x+1y=1n!\frac{1}{x} + \frac{1}{y} = \frac{1}{n!}

The count grows very fast with n, so return it modulo 109+7{10^9 + 7}.

Function Signature

def count_pairs(n: int) -> int:

Rules

  • Count ordered pairs: when x != y , (x, y) and (y, x) are two different pairs.
  • Both x and y must be positive integers.
  • Return the count modulo 1000000007 .

Constraints

  • 1 <= n <= 10^6

Examples

Input: n = 1
Output: 1

Here n! = 1, and the only solution is (2, 2), since 1/2 + 1/2 = 1.

Input: n = 2
Output: 3

Here n! = 2, and the solutions are (3, 6), (4, 4) and (6, 3). For instance, 1/3 + 1/6 = 1/2.

Input: n = 3
Output: 9

Here n! = 6. The solutions are (7, 42), (8, 24), (9, 18), (10, 15), (12, 12) and the four reversals (15, 10), (18, 9), (24, 8) and (42, 7).