Check Pronic Number in Python

Beginner
⏱️ 10 min read
📚 Updated: May 2026
🎯 2 Code Examples
Number theory

What you’ll learn

  • What a pronic number is: product of two consecutive integers.
  • A simple and safe integer check in Python.
  • How to list pronic values in a range with reusable code.

Overview

A number is pronic if it can be written as k*(k+1). We test a single number and then list all pronic numbers in a small range.

Two examples

One program checks one value, another prints all pronic numbers from 1 to 20.

Live preview

Interactive checker shows whether n = k*(k+1) and reports k if found.

Interview clarity

Definition, algorithm, edge cases, complexity, and FAQ in one place.

Prerequisites

Basic Python loops and integer multiplication are enough.

  • Write functions using def and conditionals using if.
  • Use for loops and integer math expressions like k * (k + 1).

What is a pronic number?

A pronic number is any number of the form k*(k+1) where k >= 0.

Examples: 2 = 1*2, 6 = 2*3, 12 = 3*4, 20 = 4*5, and 0 = 0*1.

Pronic n = k(k+1)
Square n = k^2
Neither e.g. 1, 3, 5

Why checking up to sqrt(n) works

For n = k*(k+1), k is near sqrt(n). That means only small k values are needed before crossing n.

Worked check: n = 12

Try k = 0, 1, 2, 3. At k = 3, 3*(3+1) = 12, so 12 is pronic.

Picture it

Pronic numbers count dots in a rectangle of size k by k+1.

6 Pronic
Reason
6 = 2*3
9 Not pronic
Reason
9 = 3*3 (not consecutive)

Takeaway: factors must be consecutive integers, not just any pair.

Live preview

Try nonnegative integers and see whether the value fits k*(k+1).

Use a nonnegative integer; very large inputs are capped.

Live result
Press "Run check".

Algorithm

Goal: decide if n = k*(k+1) for some integer k >= 0.

Reject negatives

If n < 0, return False.

Try k values

Start from k = 0, compute p = k*(k+1).

Match or stop

If p == n return True, if p > n return False.

📜 Pseudocode

Pseudocode
function isPronic(n):
    if n < 0:
        return false
    k = 0
    while true:
        p = k * (k + 1)
        if p == n:
            return true
        if p > n:
            return false
        k = k + 1
1

Check one value

Simple integer loop version. Python integers are arbitrary precision, so no overflow worries for normal interview usage.

python
def is_pronic(n: int) -> bool:
    if n < 0:
        return False

    k = 0
    while True:
        product = k * (k + 1)
        if product == n:
            return True
        if product > n:
            return False
        k += 1


number = 12
if is_pronic(number):
    print(f"{number} is a pronic number.")
else:
    print(f"{number} is not a pronic number.")
2

Pronic numbers from 1 to 20

Reuses the helper and prints matching values in range.

python
def is_pronic(n: int) -> bool:
    if n < 0:
        return False
    k = 0
    while True:
        product = k * (k + 1)
        if product == n:
            return True
        if product > n:
            return False
        k += 1


print("Pronic numbers in the range 1 to 20:")
for value in range(1, 21):
    if is_pronic(value):
        print(value, end=" ")
print()

Other approaches

Sqrt shortcut. You can check k = int(sqrt(n)) then test k*(k+1) == n.

Quadratic view. From k^2 + k - n = 0, discriminant method is another valid approach.

Interview tip: definition + integer loop is easiest to explain clearly.

❓ FAQ

A pronic number is the product of two consecutive integers: n = k*(k+1).
No. There is no integer k with k*(k+1) = 1.
Yes. 12 = 3*4, and 3 and 4 are consecutive integers.
Yes for k >= 1, because one of k and k+1 is always even. Also 0 is pronic (k = 0).
You can, but integer checks are easier to explain and safer in beginner code.
Pronic numbers are exactly twice triangular numbers.

🔄 Input / output examples

nPronic?Message
12Yes (3*4)12 is a pronic number.
9No9 is not a pronic number.
0Yes (0*1)0 is a pronic number.
2Yes (1*2)2 is a pronic number.

Edge cases and pitfalls

n = 0

Pronic if k starts at 0

Because 0 = 0*(0+1).

Negative n

Not pronic in this definition

Most beginner problems define pronic for nonnegative integers.

Consecutive factors

Do not confuse with squares

9 is 3*3, not k*(k+1), so it is not pronic.

⏱️ Time and space complexity

TaskTimeExtra space
Single n (k loop)O(sqrt(n))O(1)
Range [a, b]O((b-a)*sqrt(b))O(1)
Naive up to nO(n)O(1)

Summary

  • Definition: pronic means n = k*(k+1) for some k >= 0.
  • Method: loop k and compare k*(k+1) to n.
  • Careful: 0 is pronic, negatives are usually excluded, and squares are not automatically pronic.
Did you know?

Pronic numbers are also called oblong or rectangular because k(k+1) counts dots in a rectangle with sides k and k+1. The sequence starts 0, 2, 6, 12, 20, 30, ...

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful