Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#38 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@paramsj đang làm issue này rồi.

Từ ngày 11/10/2026.

  • #39 của @paramsj — đang mở

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cpp
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
1
Fork
6
Merge trung bình
17 giờ 52 phút
Pull request đã merge (30 ngày)
14

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của techcsispit/code-corner

Tất cả issue của techcsispit/code-corner

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.