Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Prime solution in C++ incorrectly returns true for some composite numbers

Open
#38 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@paramsj is already working on this.

Since Oct 11, 2026.

  • #39 by @paramsj — open

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
cpp
Domain
backend

Research direction

Locate the C++ solution containing isPrime and inspect the loop that checks possible divisors. Confirm the behavior with the cases 9 and 25; done means both are identified as composite. An open linked pull request (#39) already addresses this issue.

Written by the indexing model from the issue text.

Description

Describe the bug

The isPrime function in the C++ solution incorrectly identifies some composite numbers as prime.

The issue is with the loop condition i * i < n. Since it uses < instead of <=, the loop stops before checking the square root of n. For example, 9 and 25 are incorrectly considered prime because their square roots (3 and 5) are never checked as potential divisors.

Expected behavior

The function should correctly identify composite numbers like 9 and 25 as non-prime.

Fix

Changing the loop condition from i * i < n to i * i <= n ensures that divisors up to and including the square root of n are checked.

I would like to work on the fix.

Dominant language
Python
Stars
1
Forks
6
Avg merge
17h 52m
Merged PRs (30d)
14

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from techcsispit/code-corner

All issues in techcsispit/code-corner

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.