A pronic number is the product of two consecutive integers, n * (n + 1), such as 56 = 7 x 8. Pronic numbers are also called oblong or heteromecic numbers, because n * (n + 1) dots form a rectangle that is one column wider than it is tall. To check a pronic number in Java, we need one square root and one multiplication.
We meet pronic numbers in coding exercises and interview questions, and in real code whenever something is counted as “every item paired with every other item, in both orders”, such as the matches in a league where each team plays every other team at home and away.
The following example tests 56 by taking the integer part of its square root and multiplying it by the next integer.
int number = 56;
int root = (int) Math.sqrt(number); // 7
boolean pronic = root * (root + 1) == number; // true
Only one candidate is tested, namely 7 x 8, and no loop is needed. We first see why that single candidate is enough, compare it with a loop and with a test based on perfect squares, make the check safe for long values, and use it to validate a fixture list in a sports app.
1. Pronic Number Formula and Properties
A number x is pronic when some integer n exists with x = n * (n + 1). The sequence starts at n = 0, so the first pronic numbers are 0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110 and 132, as listed in OEIS A002378.

A few properties come straight from the formula, and they make good test cases for our code.
- Every pronic number is even, because one of two consecutive integers is always even.
- The n-th pronic number is twice the n-th triangular number, since n * (n + 1) / 2 is the sum 1 + 2 + … + n.
- The n-th pronic number is also the sum of the first n even numbers, for example 2 + 4 + 6 + 8 = 20.
- The number 2 is the only pronic number that is prime, because every larger pronic number has the two factors n and n + 1.
The name “rectangular number” also appears in old texts, but some authors use it for any composite number, so “pronic” or “oblong” is the clearer term.
2. Three Ways to Check a Pronic Number in Java
All three methods answer the same question with different amounts of work. The loop tries candidates one by one, the square-root method jumps to the only possible candidate, and the third method turns the question into a perfect-square test.
2.1. Looping Over Consecutive Products
The loop multiplies i * (i + 1) for i = 0, 1, 2 and stops as soon as the product reaches or passes the number. It is the version most textbooks show, and it needs about the square root of the number in passes.
static boolean isPronicLoop(int number) {
for (long i = 0; i * (i + 1) <= number; i++) {
if (i * (i + 1) == number) {
return true;
}
}
return false;
}
boolean p1 = isPronicLoop(0); // true
boolean p2 = isPronicLoop(42); // true
boolean p3 = isPronicLoop(24); // false
The counter is a long on purpose. With an int counter, the product 46340 * 46341 fits, but the next one overflows past Integer.MAX_VALUE and becomes negative, so the loop keeps running with wrong products for a large non-pronic input. A negative input fails the first comparison and returns false.
2.2. Using the Square Root
For any n greater than 0, n * (n + 1) lies between n2 and (n + 1)2, so its square root is between n and n + 1. Cutting off the fraction of the square root therefore gives n, the only candidate to test.
static boolean isPronic(long number) {
if (number < 0) {
return false;
}
long root = (long) Math.sqrt(number);
return root * (root + 1) == number;
}
boolean q1 = isPronic(56); // true
boolean q2 = isPronic(57); // false
boolean q3 = isPronic(-6); // false
boolean q4 = isPronic(3_037_000_499L * 3_037_000_500L); // true
boolean q5 = isPronic(Long.MAX_VALUE); // false
The square-root check is safe for every long, because the largest root it can produce is 3,037,000,499, and 3,037,000,499 x 3,037,000,500 still fits in a long. For a pronic input, the true square root is about n + 0.5, far from a whole number, so the rounding of Math.sqrt() never moves the cut-off value to the wrong integer.
2.3. Testing Whether 4x + 1 Is a Perfect Square
Multiplying the formula by 4 and adding 1 gives 4n(n + 1) + 1 = (2n + 1)2. So x is pronic only when 4x + 1 is the square of an odd number, and the root also tells us n.
static OptionalInt pronicIndex(int x) {
if (x < 0) {
return OptionalInt.empty();
}
long t = 4L * x + 1;
long root = (long) Math.sqrt(t);
return root * root == t ? OptionalInt.of((int) (root - 1) / 2) : OptionalInt.empty();
}
OptionalInt i56 = pronicIndex(56); // OptionalInt[7]
OptionalInt i30 = pronicIndex(30); // OptionalInt[5]
OptionalInt i50 = pronicIndex(50); // OptionalInt.empty
The pronicIndex() version is useful when the caller needs n and not only a yes or no. Returning an OptionalInt makes the “not pronic” case explicit, so the caller cannot mistake a default value such as -1 for a real index.
| Method | Work per check | Gives n | Good for |
|---|---|---|---|
| Loop over i * (i + 1) | About the square root of x | Yes, the loop counter | Teaching, small inputs |
| Square root of x | Constant | Yes, root | Default choice, any long |
| Square root of 4x + 1 | Constant | Yes, (root – 1) / 2 | Recovering n from x |
3. Pronic, Square and Triangular Numbers
Pronic numbers sit between two well-known sequences. A square number is n * n, a triangular number is n * (n + 1) / 2, and a pronic number is n * (n + 1). Mixing them up is the most common mistake in exercises that ask for one of them.
| n | Square n * n | Pronic n * (n + 1) | Triangular n * (n + 1) / 2 |
|---|---|---|---|
| 1 | 1 | 2 | 1 |
| 2 | 4 | 6 | 3 |
| 3 | 9 | 12 | 6 |
| 4 | 16 | 20 | 10 |
| 5 | 25 | 30 | 15 |
Each pronic number is twice the triangular number in its row and lies between the squares of n and n + 1, which is the fact the square-root method from section 2 depends on.
4. Generating a List of Pronic Numbers
To print pronic numbers, there is no need to test every integer. Mapping each n to n * (n + 1) produces them in order, and an IntStream or LongStream does it in one statement.
List<Integer> firstTen = IntStream.range(0, 10).map(n -> n * (n + 1)).boxed().toList(); // [0, 2, 6, 12, 20, 30, 42, 56, 72, 90]
List<Long> upTo500 = LongStream.iterate(1, n -> n * (n + 1) <= 500, n -> n + 1).map(n -> n * (n + 1)).boxed().toList(); // [2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462]
The three-argument LongStream.iterate() stops when the next product passes the limit, which is cheaper than filtering a range of 500 numbers with isPronic().
5. Validating League Fixture Counts
Say a sports app imports a season schedule for a football league in which every team plays every other team twice, once at home and once away. With t teams, each team has t – 1 home matches, so the season has t * (t – 1) fixtures, which is always a pronic number. When a file arrives with a fixture count that is not pronic, rows are missing or duplicated, and the import must stop before the schedule goes live.
static int teamsForDoubleRoundRobin(int fixtures) {
OptionalInt n = pronicIndex(fixtures);
if (n.isEmpty() || fixtures == 0) {
throw new IllegalArgumentException("Not a double round-robin schedule: " + fixtures + " fixtures");
}
return n.getAsInt() + 1;
}
int teams20 = teamsForDoubleRoundRobin(380); // 20
int teams18 = teamsForDoubleRoundRobin(306); // 18
int broken = teamsForDoubleRoundRobin(379); // IllegalArgumentException
A 20-team league has 380 fixtures, which is 19 x 20. One missing row gives 379, and the import fails with a clear message instead of publishing a schedule in which one team plays a match fewer. More number checks of this kind are listed on the Java examples page.
6. Pronic Number FAQs
Online judges test pronic programs with zero, odd numbers and huge values, which is where most submissions fail.
6.1. Is 0 a pronic number?
Yes. With n = 0, the product 0 * 1 is 0, and OEIS starts the sequence with 0. Some exercise statements count only positive pronic numbers, so check the task before returning true for 0. All methods in this article accept 0.
6.2. Are pronic numbers always even?
Yes. Of any two consecutive integers, one is even, so their product is even. A quick number % 2 != 0 check can reject odd inputs before any square root is taken.
6.3. Can a pronic number be a perfect square?
Only 0. For n greater than 0, n * (n + 1) lies strictly between the squares n2 and (n + 1)2, so it cannot be a square itself.
6.4. What is the difference between pronic and oblong numbers?
There is none. Pronic, oblong and heteromecic are three names for n * (n + 1). The word “pronic” is the common one in programming exercises, and “oblong” describes the rectangle of dots.
6.5. How do we check a pronic number without Math.sqrt()?
Use the loop from section 2, which only multiplies and compares. For very large inputs, a binary search over n between 0 and 3,037,000,499 also avoids floating point and needs at most 32 steps.
7. Conclusion
A pronic number is n * (n + 1), and the integer part of its square root is n. That fact turns the check into one multiplication, and with long arithmetic it works for every value up to Long.MAX_VALUE without overflow.
The loop version is fine for teaching, and the 4x + 1 square test recovers n when we need it, as in the fixture check. To list pronic numbers, generate them from n instead of testing every integer.
8. References
Happy Learning !!