Prime solution in C++ incorrectly returns true for some composite numbers
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 1/5
- Geschätzter Aufwand
- Unter einer Stunde
- Anfängerfreundlichkeit
- 25/100
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
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus techcsispit/code-corner
-
prime/solution.java doesn't compile: public class PrimeCheck in solution.java, README requires Solution.java with a Solution classEvtl. vergeben @tanujb03 hat das vor 1 Tag übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 82/100
techcsispit/code-corner#35 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Failed compilations always report 0.000 secondsEvtl. vergeben @Shivangi-singh18 hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 35/100
techcsispit/code-corner#37 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
run.py: Python solutions are skipped on Windows when run via python instead of python3Evtl. vergeben @tanujb03 hat das vor 1 Tag übernommen. Offenbug good first issue
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 15/100
techcsispit/code-corner#29 ·
Maintainer antworten meist innerhalb von 1 Tag
-
fibonacci/solution.c: prints negative numbers for n of 47 or more (F(90) prints -1581614984)Evtl. vergeben @tanujb03 hat das vor 1 Tag übernommen. Offenbug good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 25/100
techcsispit/code-corner#27 ·
Maintainer antworten meist innerhalb von 1 Tag
-
binary-search/Solution.java: prints -1 when the target is the last element (`9 1 3 5 7 9`) or in a 1-element list (`5 5`)Evtl. vergeben @tanujb03 hat das vor 1 Tag übernommen. Offenbug good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 22/100
techcsispit/code-corner#26 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in techcsispit/code-corner
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
vllm-project/vllm#61131 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
kubernetes-client/python#2735 ·
Maintainer antworten meist innerhalb von 1 Tag
-
desktop help wanted test
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
docs pydanty:is-working
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
pydantic/pydantic-ai#10113 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Tutorial unit test leaks sample data into tutorial doctestEvtl. vergeben @Gambit-Checkmate hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100