Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

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

Offen
#38 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@paramsj arbeitet bereits daran.

Seit 11.10.2026.

  • #39 von @paramsj — offen

Bewertung

Schwierigkeit
1/5
Geschätzter Aufwand
Unter einer Stunde
Anfängerfreundlichkeit
25/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Veraltet
Tech-Stack
cpp
Bereich
backend

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Python
Sterne
1
Forks
6
Ø Merge
17 Std. 52 Min.
Gemergte PRs (30 T.)
14

Entwicklungsumgebung

  • Kein Dockerfile und keine Docker-Compose-Datei
  • Hat eine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus techcsispit/code-corner

Alle Issues in techcsispit/code-corner

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.