Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#38 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@paramsj ci sta già lavorando.

Dal 11/10/2026.

  • #39 di @paramsj — aperta

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
cpp
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
1
Fork
6
Merge medio
17h 52m
PR unite (30g)
14

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di techcsispit/code-corner

Tutte le issue di techcsispit/code-corner

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.