Prime solution in C++ incorrectly returns true for some composite numbers
Maintainer thường phản hồi trong vòng 1 ngày
Đá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
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
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của techcsispit/code-corner
-
prime/solution.java doesn't compile: public class PrimeCheck in solution.java, README requires Solution.java with a Solution classCó thể đã có người làm @tanujb03 đã nhận 2 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
techcsispit/code-corner#35 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Failed compilations always report 0.000 secondsCó thể đã có người làm @Shivangi-singh18 đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
techcsispit/code-corner#37 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
run.py: Python solutions are skipped on Windows when run via python instead of python3Có thể đã có người làm @tanujb03 đã nhận 2 ngày trước. Đang mởbug good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 15/100
techcsispit/code-corner#29 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fibonacci/solution.c: prints negative numbers for n of 47 or more (F(90) prints -1581614984)Có thể đã có người làm @tanujb03 đã nhận 2 ngày trước. Đang mởbug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
techcsispit/code-corner#27 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
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`)Có thể đã có người làm @tanujb03 đã nhận 2 ngày trước. Đang mởbug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 22/100
techcsispit/code-corner#26 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của techcsispit/code-corner
Issue tương tự
-
pulp-cli 0.41 break username password auth in older configs (cert and key present but empty)Đang mởbug Triage-Needed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
FuRongJun-1999/dsh-memory#170 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[开源推荐] 打拼音就出篆书的输入法,附古文字创作小工具Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
521xueweihan/HelloGitHub#3940 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100