Definition
k(k+1)
Product of consecutive integers.
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.
k(k+1)
Product of consecutive integers.
Until pass n
Compare k*(k+1) with n.
0*1
Zero is pronic under this definition.
k >= 1
One of k, k+1 is always even.
Try 12 / 9
See k when it exists.
9 fails
3*3 is consecutive-equal, not consecutive.
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.
It is a friendly number-classification prompt that reinforces consecutive products, early exits, and careful edge cases like 0 and 1.
Consecutive product.
Safest beginner check.
Classic edge pair.
k by k+1 rectangle.
In short: grow k until k*(k+1) equals n or exceeds it.
Given an integer n, decide whether it equals k*(k+1) for some k >= 0.
# 12 -> 3*4 = 12 pronic
# 9 -> 3*3 = 9 not consecutive
# 0 -> 0*1 = 0 pronic
# 2 -> 1*2 = 2 pronic | Item | Type | Description |
|---|---|---|
n | int | Value to test (n >= 0 for yes). |
| Return | bool | True when some k has k*(k+1) == n. |
| Optional k | int | The consecutive starter when found. |
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 | Idea | Notes |
|---|---|---|
| Grow k | Compare k*(k+1) with n | Interview default — clearest |
| Generate | Print k*(k+1) for k = 0, 1, … | Best for listing the sequence |
| Sqrt / discriminant | Solve k² + k - n = 0 | Valid but float-sensitive |
| Goal | Pattern |
|---|---|
| Reject negatives | if n < 0: return False |
| Product | product = k * (k + 1) |
| Hit | if product == n: return True |
| Passed | if product > n: return False |
| Generate | print(k * (k + 1)) |
| Sqrt idea | k = int(n**0.5); k*(k+1) == n |
Same definition — different packaging.
k*(k+1)Clearest check for one n
for k in …Build the sequence directly
int(sqrt(n))Faster, float caveats
k*k ≠ k*(k+1)9 is square, not pronic
Reach for a pronic check whenever you need consecutive-product classification.
Definition plus a short search loop.
Print oblong numbers in a band.
k by k+1 rectangular arrays.
Pronic = 2 × triangular.
Most beginner defs use n >= 0.
Key benefit: one memorable formula — consecutive integers — with a loop that is trivial to dry-run.
Grows k from 0 and reports the matching pair when n is pronic.
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.
A clear integer loop that finds k or proves none exists.
Simple integer loop version. Python integers are arbitrary precision, so no overflow worries for normal interview usage.
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.") Products climb 0, 2, 6, 12… At k = 3 the product equals 12, so the helper returns True.
Reuse the helper to list nearby pronic values.
Reuses the helper and prints matching values in range.
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() Within 1..20 the hits are 2, 6, 12, and 20. 0 is pronic too but sits outside this printed band.
Build the sequence directly instead of filtering every integer.
print("Pronic numbers for k = 0 to 6:")
for k in range(0, 7):
value = k * (k + 1)
print(f"{k} * {k + 1} = {value}") When you only need the sequence, multiplying consecutive integers is cheaper than testing every n in a range.
This tutorial defines pronic for nonnegative n.
Start at k = 0 and climb.
Equal means yes; greater means no.
True with k, or False.
Compare the grow-k loop on a yes case and a no case.
| k | k*(k+1) | vs 12 | vs 9 |
|---|---|---|---|
0 | 0 | < | < |
1 | 2 | < | < |
2 | 6 | < | < |
3 | 12 | = yes | > no (already passed 9) |
12 hits exactly at k = 3; 9 is skipped between 6 and 12.
Where pronic checks show up beyond the interview prompt.
Definition + short search loop.
Example: is_pronic(12).
Find oblong values in a band.
Example: 2 6 12 20.
Build with k*(k+1).
Example: Example 3.
Dots in a k by k+1 grid.
Example: oblong name.
Pronic = 2 × triangular.
Example: FAQ follow-up.
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.
Why the grow-k loop works well for beginners and interviews.
Dry-run 12 on paper in a few steps.
No float rounding surprises.
Stop as soon as the product passes n.
k*(k+1) builds the sequence without scanning.
Pro Tip: lead with the integer loop; mention sqrt only as an optional optimization aside.
Small habits that keep pronic solutions interview-ready.
Return False for n < 0.
product > n means failure.
0 yes, 1 no — classic traps.
Use k*(k+1) if you need the sequence.
Sqrt is optional after the clear loop.
Pro Tip: sanity-check 0, 12, 9, and 1 — if those four behave, your logic is solid.
Mistakes that commonly break pronic-number programs.
Thinking 9 = 3*3 counts.
→ Factors must be consecutive: k and k+1.
Forgetting 0 = 0*1.
→ Start k at 0.
No integer k works.
→ Return False for 1.
Outside this tutorial’s definition.
→ Reject n < 0.
Rounding can mis-identify large n.
→ Prefer the integer loop, or verify carefully.
Handle these before claiming the check is complete.
0 = 0 * 1.
No integer k works.
3*3 is not consecutive.
Most beginner problems use n >= 0.
3 * 4 = 12.
1 * 2 = 2.
Handy follow-ups interviewers sometimes ask.
Try these variations to lock in the pattern.
Quick Takeaway: n is pronic when some k >= 0 satisfies k * (k + 1) == n.
| Approach | Time | Extra space |
|---|---|---|
| Grow-k loop | O(sqrt(n)) | O(1) |
| Generate first m values | O(m) | O(1) |
| Range scan 1..U | O(U sqrt(U)) worst | O(1) |
Since k*(k+1) grows like k², the search stops after about sqrt(n) steps.
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.
Classify consecutive products the interview-friendly way.
k*(k+1)
Definitiongrow until
Method0 yes / 1 no
Guardsnot squares
PitfallO(√n)
AnalysisPronic 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, ...
Learn how to check whether a number is composite in Python.
9 people found this page helpful