Check Pronic Number in Python

Beginner
⏱️ 10 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
Number Theory

What You’ll Learn

A pronic number (also called oblong or rectangular) equals k * (k + 1) for some integer k >= 0. Examples: 0, 2, 6, 12, 20. Non-examples: 1, 9, 15. This tutorial covers an integer loop check, a live finder for k, worked Python examples, edge cases, and complexity.

Definition

k(k+1)

Product of consecutive integers.

Grow k

Until pass n

Compare k*(k+1) with n.

0 Counts

0*1

Zero is pronic under this definition.

Usually Even

k >= 1

One of k, k+1 is always even.

Live Preview

Try 12 / 9

See k when it exists.

Not a Square

9 fails

3*3 is consecutive-equal, not consecutive.

Introduction

A pronic number is any nonnegative integer of the form k * (k + 1). So 12 = 3 * 4 is pronic, while 9 = 3 * 3 is not — the factors must be consecutive.

Interviews usually want a clear integer loop: grow k from 0, compute the product, and stop when you hit n or pass it. That approach is easy to explain and avoids float-rounding debates.

Why it matters?

It is a friendly number-classification prompt that reinforces consecutive products, early exits, and careful edge cases like 0 and 1.

Key Highlights

k(k+1)

Consecutive product.

Integer Loop

Safest beginner check.

0 Yes, 1 No

Classic edge pair.

Oblong Shape

k by k+1 rectangle.

In short: grow k until k*(k+1) equals n or exceeds it.

📝 Problem & Approach

Given an integer n, decide whether it equals k*(k+1) for some k >= 0.

python
# 12 -> 3*4 = 12   pronic
# 9  -> 3*3 = 9    not consecutive
# 0  -> 0*1 = 0    pronic
# 2  -> 1*2 = 2    pronic

Inputs & Outputs

ItemTypeDescription
nintValue to test (n >= 0 for yes).
ReturnboolTrue when some k has k*(k+1) == n.
Optional kintThe consecutive starter when found.

Minimal workflow

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

Method comparison

MethodIdeaNotes
Grow kCompare k*(k+1) with nInterview default — clearest
GeneratePrint k*(k+1) for k = 0, 1, …Best for listing the sequence
Sqrt / discriminantSolve k² + k - n = 0Valid but float-sensitive

⚡ Quick Reference

GoalPattern
Reject negativesif n < 0: return False
Productproduct = k * (k + 1)
Hitif product == n: return True
Passedif product > n: return False
Generateprint(k * (k + 1))
Sqrt ideak = int(n**0.5); k*(k+1) == n

📋 Loop vs Generate vs Sqrt

Same definition — different packaging.

Grow k
k*(k+1)

Clearest check for one n

Generate
for k in …

Build the sequence directly

Sqrt
int(sqrt(n))

Faster, float caveats

vs square
k*k ≠ k*(k+1)

9 is square, not pronic

Context

When This Problem Shows Up

Reach for a pronic check whenever you need consecutive-product classification.

  1. Interview warm-ups

    Definition plus a short search loop.

  2. Sequence listing

    Print oblong numbers in a band.

  3. Geometry intuition

    k by k+1 rectangular arrays.

  4. Triangular cousins

    Pronic = 2 × triangular.

  5. Not for negatives

    Most beginner defs use n >= 0.

Key benefit: one memorable formula — consecutive integers — with a loop that is trivial to dry-run.

🔮 Live Preview

Grows k from 0 and reports the matching pair when n is pronic.

Use a nonnegative integer; very large inputs are capped.

Live result
Press “Run check”.

Examples Gallery

Three complete Python programs — check 12, list pronic values from 1 to 20, and generate the sequence by multiplying consecutive integers. Click View Output to reveal sample console results.

📚 Getting Started

A clear integer loop that finds k or proves none exists.

Example 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.")

How It Works

Products climb 0, 2, 6, 12… At k = 3 the product equals 12, so the helper returns True.

⚡ Hunting in a Range

Reuse the helper to list nearby pronic values.

Example 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()

How It Works

Within 1..20 the hits are 2, 6, 12, and 20. 0 is pronic too but sits outside this printed band.

Example 3 — Generate by Multiplying Consecutive Integers

Build the sequence directly instead of filtering every integer.

python
print("Pronic numbers for k = 0 to 6:")
for k in range(0, 7):
    value = k * (k + 1)
    print(f"{k} * {k + 1} = {value}")

How It Works

When you only need the sequence, multiplying consecutive integers is cheaper than testing every n in a range.

🧠 How the Algorithm Decides

1

Reject n < 0

This tutorial defines pronic for nonnegative n.

Guard
2

Compute k*(k+1)

Start at k = 0 and climb.

Loop
3

Compare with n

Equal means yes; greater means no.

Rule
=

Return the verdict

True with k, or False.

🔎 Worked Walkthrough — 12 vs 9

Compare the grow-k loop on a yes case and a no case.

kk*(k+1)vs 12vs 9
00<<
12<<
26<<
312= yes> no (already passed 9)

12 hits exactly at k = 3; 9 is skipped between 6 and 12.

Use Cases

Where pronic checks show up beyond the interview prompt.

1. Interview Classics

Definition + short search loop.

Example: is_pronic(12).

2. Range Listing

Find oblong values in a band.

Example: 2 6 12 20.

3. Sequence Generation

Build with k*(k+1).

Example: Example 3.

4. Rectangle Counting

Dots in a k by k+1 grid.

Example: oblong name.

5. Triangular Link

Pronic = 2 × triangular.

Example: FAQ follow-up.

6. Next: Composite

Continue the interview chain.

Example: related CTA.

Pro Tip: open with “n is pronic iff n = k*(k+1) for some k >= 0” before coding.

Advantages

Why the grow-k loop works well for beginners and interviews.

  1. 1. Easy to Trace

    Dry-run 12 on paper in a few steps.

  2. 2. Exact Integers

    No float rounding surprises.

  3. 3. Early Exit

    Stop as soon as the product passes n.

  4. 4. Generates Cleanly

    k*(k+1) builds the sequence without scanning.

Pro Tip: lead with the integer loop; mention sqrt only as an optional optimization aside.

Usage Tips

Small habits that keep pronic solutions interview-ready.

  1. 1. Guard Negatives

    Return False for n < 0.

  2. 2. Stop When Past n

    product > n means failure.

  3. 3. Mention 0 and 1

    0 yes, 1 no — classic traps.

  4. 4. Generate When Listing

    Use k*(k+1) if you need the sequence.

  5. 5. Prefer Integers

    Sqrt is optional after the clear loop.

Pro Tip: sanity-check 0, 12, 9, and 1 — if those four behave, your logic is solid.

Common Pitfalls

Mistakes that commonly break pronic-number programs.

  1. 1. Treating Squares as Pronic

    Thinking 9 = 3*3 counts.

    → Factors must be consecutive: k and k+1.

  2. 2. Rejecting Zero

    Forgetting 0 = 0*1.

    → Start k at 0.

  3. 3. Calling 1 Pronic

    No integer k works.

    → Return False for 1.

  4. 4. Accepting Negatives

    Outside this tutorial’s definition.

    → Reject n < 0.

  5. 5. Blind Float Sqrt

    Rounding can mis-identify large n.

    → Prefer the integer loop, or verify carefully.

Edge Cases

Handle these before claiming the check is complete.

n = 0

Pronic

0 = 0 * 1.

n = 1

Not pronic

No integer k works.

n = 9

Square, not pronic

3*3 is not consecutive.

Negative

Excluded here

Most beginner problems use n >= 0.

12

Classic yes

3 * 4 = 12.

2

Smallest positive

1 * 2 = 2.

⚖️ Facts Worth Knowing

Handy follow-ups interviewers sometimes ask.

  • Even for k >= 1. One of k and k+1 is always even.
  • Triangular link. Pronic numbers are twice triangular numbers.
  • Names. Also called oblong or rectangular numbers.
  • Sequence. 0, 2, 6, 12, 20, 30, 42, …

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Prove 12

  • Show k = 3
  • 3 * 4 = 12

2. Reject 9

  • Pass between 6 and 12
  • Confirm False

3. List 1..20

  • Reproduce Example 2
  • Expect 2 6 12 20

4. Generate

  • Print k = 0..6
  • Match Example 3

Notes

  • Definition: pronic means n = k*(k+1) for some k >= 0.
  • Loop: grow k until the product equals n or exceeds it.
  • Careful: 0 is pronic, negatives are usually excluded, and squares are not automatically pronic.
  • Sqrt shortcut: check k = int(sqrt(n)) then k*(k+1) == n. Discriminant method also works. Interview tip: definition + integer loop is easiest to explain.

Quick Takeaway: n is pronic when some k >= 0 satisfies k * (k + 1) == n.

⏱️ Time and Space Complexity

ApproachTimeExtra space
Grow-k loopO(sqrt(n))O(1)
Generate first m valuesO(m)O(1)
Range scan 1..UO(U sqrt(U)) worstO(1)

Since k*(k+1) grows like k², the search stops after about sqrt(n) steps.

Wrap Up

🎉 Conclusion

A pronic number equals the product of two consecutive integers. Grow k from 0, compare k*(k+1) with n, and remember the edge cases: 0 is yes, 1 and squares like 9 are not.

Practice the three examples above, then continue to composite numbers.

n = k*(k+1) means pronic; consecutive factors only.

💡 Best Practices

✅ Do

  • State n = k*(k+1)
  • Start k at 0
  • Stop when product > n
  • Treat 0 as pronic
  • Prefer integer loops first

❌ Don’t

  • Accept 9 as pronic
  • Call 1 pronic
  • Ignore negatives without a policy
  • Rely on float sqrt alone
  • Forget consecutive means k and k+1

Key Takeaways

Knowledge Unlocked

Five things to remember about pronic numbers

Classify consecutive products the interview-friendly way.

5
Core concepts
k 02

Loop

grow until

Method
0 03

Edges

0 yes / 1 no

Guards
9 04

Trap

not squares

Pitfall
O 05

Cost

O(√n)

Analysis

❓ Frequently Asked Questions

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.
Yes. 0 = 0*1.
No. 9 is 3*3, not consecutive integers.
State the definition, then walk a small k loop until the product passes n.

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, ...

Continue to Composite Number

Learn how to check whether a number is composite in Python.

Composite number tutorial →

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